Module: kamailio
Branch: master
Commit: bc9308eb928b67c485e53917b63ff0215677f13e
URL:
https://github.com/kamailio/kamailio/commit/bc9308eb928b67c485e53917b63ff02…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-06-15T11:30:19+02:00
Merge pull request #205 from kamailio/db_text_patch
db_text : memory allocation/release issues in raw query
---
Modified: modules/db_text/dbt_base.c
Modified: modules/db_text/dbt_raw_query.c
Modified: modules/db_text/dbt_raw_util.c
---
Diff:
https://github.com/kamailio/kamailio/commit/bc9308eb928b67c485e53917b63ff02…
Patch:
https://github.com/kamailio/kamailio/commit/bc9308eb928b67c485e53917b63ff02…
---
diff --git a/modules/db_text/dbt_base.c b/modules/db_text/dbt_base.c
index 7ca4563..6d70ce5 100644
--- a/modules/db_text/dbt_base.c
+++ b/modules/db_text/dbt_base.c
@@ -503,7 +503,8 @@ int dbt_delete(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
int _n)
_drp = _drp0;
}
- dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
+ if( ((dbt_con_p)_h->tail)->affected )
+ dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
/* dbt_print_table(_tbc, NULL); */
@@ -587,7 +588,8 @@ int dbt_update(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t*
_v,
_drp = _drp->next;
}
- dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
+ if( ((dbt_con_p)_h->tail)->affected )
+ dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
/* dbt_print_table(_tbc, NULL); */
diff --git a/modules/db_text/dbt_raw_query.c b/modules/db_text/dbt_raw_query.c
index ad13600..143a585 100644
--- a/modules/db_text/dbt_raw_query.c
+++ b/modules/db_text/dbt_raw_query.c
@@ -120,10 +120,15 @@ int dbt_raw_query_select(db1_con_t* _h, str* _s, db1_res_t** _r)
dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
+ _tbc = NULL;
res = dbt_query(_h, _k, _op, _v, result_cols, nc, cols, NULL, _r);
error:
+
+ if(_tbc)
+ dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
+
if(tokens) {
for (i = 0; *(tokens + i); i++) {
pkg_free(*(tokens + i));
diff --git a/modules/db_text/dbt_raw_util.c b/modules/db_text/dbt_raw_util.c
index aba55b8..f000f3b 100644
--- a/modules/db_text/dbt_raw_util.c
+++ b/modules/db_text/dbt_raw_util.c
@@ -141,6 +141,7 @@ void dbt_clean_where(int n, db_key_t* _k, db_op_t* _op, db_val_t* _v)
if(_k) {
for(i=0; i < n; i++) {
pkg_free(_k[i]->s);
+ pkg_free(_k[i]);
}
pkg_free(_k);
}
@@ -167,7 +168,7 @@ int dbt_build_where(char* where, db_key_t** _k, db_op_t** _o,
db_val_t** _v)
char** _o1 = NULL;
db_val_t* _v1 = NULL;
regmatch_t* matches = NULL;
- int l;
+ int n, l;
int len;
regex_t preg;
int offset = 0;
@@ -214,9 +215,9 @@ int dbt_build_where(char* where, db_key_t** _k, db_op_t** _o,
db_val_t** _v)
// needs changes in dbt_query / dbt_row_match
l = matches[2].rm_eo - matches[2].rm_so;
- _k1[idx] = pkg_malloc(sizeof(str)+l+1);
+ _k1[idx] = pkg_malloc(sizeof(db_key_t));
_k1[idx]->len = l;
- _k1[idx]->s = (char*) (_k1[idx]+sizeof(str));
+ _k1[idx]->s = pkg_malloc(sizeof(char) * (l+1));
strncpy(_k1[idx]->s, buffer+matches[2].rm_so, l);
_k1[idx]->s[l]='\0';
@@ -237,11 +238,11 @@ int dbt_build_where(char* where, db_key_t** _k, db_op_t** _o,
db_val_t** _v)
_v1[idx].val.str_val.s = pkg_malloc(l+1);
strncpy(_v1[idx].val.str_val.s, buffer+matches[5].rm_so, l);
}
-/* int n;
- for(n=0; n < MAX_MATCH; n++) {
- LM_ERR("MATCH RESULT %d - %d,%d\n", n, matches[n].rm_so, matches[n].rm_eo);
- }
-*/
+
+// for(n=0; n < MAX_MATCH; n++) {
+// LM_ERR("MATCH RESULT %d - %d,%d\n", n, matches[n].rm_so,
matches[n].rm_eo);
+// }
+
if(matches[0].rm_eo != -1)
offset += matches[0].rm_eo;