Browse Source

lib/srdb1: Fix memory leak with string memory in db_val2pv_spec()

Alex Hermann 14 years ago
parent
commit
b4af74a164
2 changed files with 10 additions and 2 deletions
  1. 6 1
      lib/srdb1/db_ut.c
  2. 4 1
      lib/srdb1/db_ut.h

+ 6 - 1
lib/srdb1/db_ut.c

@@ -491,10 +491,15 @@ int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t *pvs)
 	if (pv_set_spec_value(msg, pvs, 0, &pv) != 0)
 	{
 		LM_ERR("Failed to add value to spec\n");
-		if (pv.flags == PV_VAL_STR)
+		if (pv.flags == PV_VAL_STR && pv.rs.len > 0)
 			pkg_free(pv.rs.s);
 		return -1;
 	}
 
+	/* free string memory */
+	if (pv.flags == PV_VAL_STR && pv.rs.len > 0) {
+		pkg_free(pv.rs.s);
+	}
+
 	return 0;
 }

+ 4 - 1
lib/srdb1/db_ut.h

@@ -208,7 +208,10 @@ int db_print_set(const db1_con_t* _c, char* _b, const int _l,
 
 
 /**
- * Convert db_val to pv_spec_t
+ * Convert db_val_t to pv_spec_t
+ *
+ * On success, when the PV type is string and longer than 0 chars,
+ * the string must be freed by the caller after use.
  * 
  * \param msg sip msg structure
  * \param dbval database value