浏览代码

db_mysql: properly free db result structure if db_mysql_convert_result() fails

- reported by Torrey Searle, FS#420
Daniel-Constantin Mierla 11 年之前
父节点
当前提交
37983c9f57
共有 2 个文件被更改,包括 6 次插入4 次删除
  1. 4 4
      modules/db_mysql/km_dbase.c
  2. 2 0
      modules/db_mysql/km_res.c

+ 4 - 4
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) );

+ 2 - 0
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;
 	}