[asterisk-commits] branch kpfleming/stringfields - r7763 /team/kpfleming/stringfields/utils.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 3 20:18:47 CST 2006


Author: kpfleming
Date: Tue Jan  3 20:18:46 2006
New Revision: 7763

URL: http://svn.digium.com/view/asterisk?rev=7763&view=rev
Log:
ensure that pool grows enough for current allocation to succeed

Modified:
    team/kpfleming/stringfields/utils.c

Modified: team/kpfleming/stringfields/utils.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/stringfields/utils.c?rev=7763&r1=7762&r2=7763&view=diff
==============================================================================
--- team/kpfleming/stringfields/utils.c (original)
+++ team/kpfleming/stringfields/utils.c Tue Jan  3 20:18:46 2006
@@ -944,15 +944,19 @@
 	if (__builtin_expect(needed > pool->space, 0)) {
 		int index;
 		char *new_base;
-
-		if (!(new_base = realloc(pool->base, pool->size * 2)))
+		size_t new_size = pool->size * 2;
+
+		while (new_size < (pool->used + needed))
+			new_size *= 2;
+
+		if (!(new_base = realloc(pool->base, new_size)))
 			return NULL;
 
 		for (index = 0; index < num_fields; index++)
 			fields[index] = new_base + (fields[index] - pool->base);
 		pool->base = new_base;
-		pool->space += pool->size;
-		pool->size *= 2;
+		pool->space += new_size - pool->size;
+		pool->size = new_size;
 	}
 
 	result = pool->base + pool->used;



More information about the asterisk-commits mailing list