From 4dbff66fff81f929118f18338f0a57fac674d4f9 Mon Sep 17 00:00:00 2001 From: Luis Azedo Date: Thu, 11 Jun 2015 17:16:09 +0100 Subject: [PATCH 1/2] db_text : only mark changed if there was a real change --- modules/db_text/dbt_base.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/db_text/dbt_base.c b/modules/db_text/dbt_base.c index 7ca45638644..6d70ce543b3 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); */ From d4f7cf1d933d74a55dfee0eafcf646a6165b12d6 Mon Sep 17 00:00:00 2001 From: Luis Azedo Date: Thu, 11 Jun 2015 17:17:08 +0100 Subject: [PATCH 2/2] db_text : memory allocation / release in raw query --- modules/db_text/dbt_raw_query.c | 5 +++++ modules/db_text/dbt_raw_util.c | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/db_text/dbt_raw_query.c b/modules/db_text/dbt_raw_query.c index ad13600edf6..143a585692a 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 aba55b81daf..f000f3b084a 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;