Module: sip-router
Branch: master
Commit: 37983c9f57536c57c5d34ce2d8a1c8f411e61e39
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=37983c9f57536c57c5d34ce2d8a1c8f411e61e39

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
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

---

 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 7beaf91..0ab9066 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -251,12 +251,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;
        }
 


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to