[sr-dev] git:master:d4f7cf1d: db_text : memory allocation / release in raw query

Luis Azedo luis.azedo at factorlusitano.com
Mon Jun 15 11:30:24 CEST 2015


Module: kamailio
Branch: master
Commit: d4f7cf1d933d74a55dfee0eafcf646a6165b12d6
URL: https://github.com/kamailio/kamailio/commit/d4f7cf1d933d74a55dfee0eafcf646a6165b12d6

Author: Luis Azedo <luis.azedo at factorlusitano.com>
Committer: Luis Azedo <luis.azedo at factorlusitano.com>
Date: 2015-06-11T17:17:08+01:00

db_text : memory allocation / release in raw query

---

Modified: modules/db_text/dbt_raw_query.c
Modified: modules/db_text/dbt_raw_util.c

---

Diff:  https://github.com/kamailio/kamailio/commit/d4f7cf1d933d74a55dfee0eafcf646a6165b12d6.diff
Patch: https://github.com/kamailio/kamailio/commit/d4f7cf1d933d74a55dfee0eafcf646a6165b12d6.patch

---

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;
 




More information about the sr-dev mailing list