[asterisk-commits] kpfleming: trunk r197775 - /trunk/main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 28 15:37:08 CDT 2009


Author: kpfleming
Date: Thu May 28 15:36:49 2009
New Revision: 197775

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=197775
Log:
Ensure that accidental calls to ast_string_field_free_memory() on embedded stringfield pools are safe.

It is possible for a stringfield manager structure (and pool) structure to be allocated
as part of a larger structure allocation (using ast_calloc_with_strinfields()); when
this is done, the stringfield pool cannot be separately freed, but users of the tructure
may not be aware (and shouldn't have to be aware) of whether the pool was embedded.
This patch modifies the behavior so that they can always call ast_string_field_free_memory()
and the function will do the right thing for both embedded and non-embedded situations.


Modified:
    trunk/main/utils.c

Modified: trunk/main/utils.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/utils.c?view=diff&rev=197775&r1=197774&r2=197775
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Thu May 28 15:36:49 2009
@@ -1559,11 +1559,17 @@
 		return add_string_pool(mgr, pool_head, needed, file, lineno, func);
 	}
 
+	/* if there is an embedded pool, we can't actually release *all*
+	 * pools, we must keep the embedded one. if the caller is about
+	 * to free the structure that contains the stringfield manager
+	 * and embedded pool anyway, it will be freed as part of that
+	 * operation.
+	 */
+	if ((needed < 0) && mgr->embedded_pool) {
+		needed = 0;
+	}
+
 	if (needed < 0) {		/* reset all pools */
-		if (*pool_head == NULL) {
-			ast_log(LOG_WARNING, "trying to reset empty pool\n");
-			return -1;
-		}
 		cur = *pool_head;
 	} else if (mgr->embedded_pool) { /* preserve the embedded pool */
 		preserve = mgr->embedded_pool;




More information about the asterisk-commits mailing list