[svn-commits] rizzo: trunk r48520 - /trunk/main/utils.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Dec 16 04:23:08 MST 2006


Author: rizzo
Date: Sat Dec 16 05:23:07 2006
New Revision: 48520

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48520
Log:
forgot this part...


Modified:
    trunk/main/utils.c

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=48520&r1=48519&r2=48520
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Sat Dec 16 05:23:07 2006
@@ -1003,19 +1003,15 @@
 	if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
 		if (max_len && max_len < need)	/* truncate as needed */
 			need = max_len;
-
-		/* We can only realloc malloc'ed space. */
-		if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC)
+		else if (max_len == 0)	/* if unbounded, give more room for next time */
+			need += 16 + need/4;
+		if (0)	/* debugging */
+			ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need);
+		if (ast_str_make_space(buf, need)) {
+			ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need);
 			return AST_DYNSTR_BUILD_FAILED;
-		*buf = ast_realloc(*buf, need + sizeof(struct ast_str));
-		if (*buf == NULL) /* XXX watch out, we leak memory here */
-			return AST_DYNSTR_BUILD_FAILED;
-		(*buf)->len = need;
-
+		}
 		(*buf)->str[offset] = '\0';	/* Truncate the partial write. */
-
-		if ((*buf)->ts != DS_ALLOCA)
-			pthread_setspecific((*buf)->ts->key, *buf);
 
 		/* va_end() and va_start() must be done before calling
 		 * vsnprintf() again. */



More information about the svn-commits mailing list