summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/main/utils.c b/main/utils.c
index 3a095ca7b..e3bb36e03 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2099,9 +2099,13 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
for (pool = pool_head, prev = NULL; pool; prev = pool, pool = pool->prev) {
if ((ptr >= pool->base) && (ptr <= (pool->base + pool->size))) {
pool->active -= AST_STRING_FIELD_ALLOCATION(ptr);
- if ((pool->active == 0) && prev) {
- prev->prev = pool->prev;
- ast_free(pool);
+ if (pool->active == 0) {
+ if (prev) {
+ prev->prev = pool->prev;
+ ast_free(pool);
+ } else {
+ pool->used = 0;
+ }
}
break;
}
@@ -2150,6 +2154,11 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
/* Are we out of memory? */
return;
}
+ if (res == 0) {
+ __ast_string_field_release_active(*pool_head, *ptr);
+ *ptr = __ast_string_field_empty;
+ return;
+ }
needed = (size_t)res + 1; /* NUL byte */
if (needed > available) {