Przeglądaj źródła

- fixed freeing NULL pointers - in case of error, db_free_columns() may be
internally called by other functions or directly by db_free_result(),
resulting in double free. Reported by Richard Revels, credits to Bogdan


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4783 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 lat temu
rodzic
commit
537075c821
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5 3
      lib/srdb1/db_res.c

+ 5 - 3
lib/srdb1/db_res.c

@@ -79,9 +79,11 @@ inline int db_free_columns(db_res_t* _r)
 	LM_DBG("freeing %d columns\n", RES_COL_N(_r));
 	/* free memory previously allocated to save column names */
 	for(col = 0; col < RES_COL_N(_r); col++) {
-		LM_DBG("freeing RES_NAMES[%d] at %p\n", col, RES_NAMES(_r)[col]);
-		pkg_free((str *)RES_NAMES(_r)[col]);
-		RES_NAMES(_r)[col] = NULL;
+		if (RES_NAMES(_r)[col]!=NULL) {
+			LM_DBG("freeing RES_NAMES[%d] at %p\n", col, RES_NAMES(_r)[col]);
+			pkg_free((str *)RES_NAMES(_r)[col]);
+			RES_NAMES(_r)[col] = NULL;
+		}
 	}
 	/* free names and types */
 	if (RES_NAMES(_r)) {