[sr-dev] git:4.1: db_mysql: properly free db result structure if db_mysql_convert_result() fails
Daniel-Constantin Mierla
miconda at gmail.com
Mon May 12 16:35:21 CEST 2014
Module: sip-router
Branch: 4.1
Commit: 402e2122d1aa353ee8c10321aa1eb9315a81cd81
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=402e2122d1aa353ee8c10321aa1eb9315a81cd81
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Wed Apr 16 19:43:45 2014 +0200
db_mysql: properly free db result structure if db_mysql_convert_result() fails
- reported by Torrey Searle, FS#420
(cherry picked from commit 37983c9f57536c57c5d34ce2d8a1c8f411e61e39)
---
modules/db_mysql/km_dbase.c | 8 ++++----
modules/db_mysql/km_res.c | 2 ++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index f644dea..a1e7ac7 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -190,12 +190,12 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
if (db_mysql_convert_result(_h, *_r) < 0) {
LM_ERR("error while converting result\n");
LM_DBG("freeing result set at %p\n", _r);
- pkg_free(*_r);
- *_r = 0;
/* all mem on Kamailio API side is already freed by
* db_mysql_convert_result in case of error, but we also need
- * to free the mem from the mysql lib side */
- mysql_free_result(RES_RESULT(*_r));
+ * to free the mem from the mysql lib side, internal pkg for it
+ * and *_r */
+ db_mysql_free_result(_h, *_r);
+ *_r = 0;
#if (MYSQL_VERSION_ID >= 40100)
while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
diff --git a/modules/db_mysql/km_res.c b/modules/db_mysql/km_res.c
index 965e6dc..3f1ca26 100644
--- a/modules/db_mysql/km_res.c
+++ b/modules/db_mysql/km_res.c
@@ -69,6 +69,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
}
if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
+ RES_COL_N(_r) = 0;
LM_ERR("could not allocate columns\n");
return -3;
}
@@ -173,6 +174,7 @@ static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
if (db_allocate_rows(_r) < 0) {
LM_ERR("could not allocate rows");
+ RES_ROW_N(_r) = 0;
return -2;
}
More information about the sr-dev
mailing list