aboutsummaryrefslogtreecommitdiffstats
path: root/main/utils.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-16 11:23:07 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-16 11:23:07 +0000
commit91101a1b97abd029c03640350755d2f4d99959d8 (patch)
treea216720663ca64f151fddb0f04eafb88c40b204a /main/utils.c
parentee5146aeb7ab6e91c4275c7fa0a015302ef49b4c (diff)
forgot this part...
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@48520 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/main/utils.c b/main/utils.c
index 65d6d20d6..6728fce7e 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1003,20 +1003,16 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len,
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)
- return AST_DYNSTR_BUILD_FAILED;
- *buf = ast_realloc(*buf, need + sizeof(struct ast_str));
- if (*buf == NULL) /* XXX watch out, we leak memory here */
+ 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)->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. */
return AST_DYNSTR_BUILD_RETRY;