Fix unintential memory retention in stringfields.

* Fix missing / unreachable calls to __ast_string_field_release_active.
* Reset pool->used to zero when the current pool->active reaches zero.

ASTERISK-24307 #close
Reported by: Etienne Lessard
Tested by: ibercom, Etienne Lessard
Review: https://reviewboard.asterisk.org/r/4114/
........

Merged revisions 427380 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 427381 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 427382 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@427384 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Corey Farrell
2014-11-06 09:17:50 +00:00
parent c056506d84
commit 433366ab90
2 changed files with 34 additions and 23 deletions

View File

@@ -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) {