diff options
author | Corey Farrell <git@cfware.com> | 2014-11-06 09:17:50 +0000 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2014-11-06 09:17:50 +0000 |
commit | 433366ab90ba5a53e7b215076dd747e55beec80f (patch) | |
tree | 23f81cc48bd767e91d2a23f7caf195771e4e228f /include | |
parent | c056506d848e0b4e1a23a6f88400183ba46c8dd3 (diff) |
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
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/stringfields.h | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h index 9f4a1ae69..dc70960dc 100644 --- a/include/asterisk/stringfields.h +++ b/include/asterisk/stringfields.h @@ -316,26 +316,28 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, */ #define ast_string_field_ptr_set(x, ptr, data) ast_string_field_ptr_set_by_fields((x)->__field_mgr_pool, (x)->__field_mgr, ptr, data) -#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \ -({ \ - int __res__ = 0; \ - const char *__d__ = (data); \ - size_t __dlen__ = (__d__) ? strlen(__d__) + 1 : 1; \ - ast_string_field *__p__ = (ast_string_field *) (ptr); \ - if (__dlen__ == 1) { \ - __ast_string_field_release_active(field_mgr_pool, *__p__); \ - *__p__ = __ast_string_field_empty; \ - } else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \ - (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \ - (*__p__ = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__))) { \ - if (*__p__ != (*ptr)) { \ - __ast_string_field_release_active(field_mgr_pool, (*ptr)); \ - } \ - memcpy(* (void **) __p__, __d__, __dlen__); \ - } else { \ - __res__ = -1; \ - } \ - __res__; \ +#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \ +({ \ + int __res__ = 0; \ + const char *__d__ = (data); \ + size_t __dlen__ = (__d__) ? strlen(__d__) + 1 : 1; \ + ast_string_field *__p__ = (ast_string_field *) (ptr); \ + ast_string_field target = *__p__; \ + if (__dlen__ == 1) { \ + __ast_string_field_release_active(field_mgr_pool, *__p__); \ + *__p__ = __ast_string_field_empty; \ + } else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \ + (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \ + (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__))) { \ + if (target != *__p__) { \ + __ast_string_field_release_active(field_mgr_pool, *__p__); \ + *__p__ = target; \ + } \ + memcpy(* (void **) __p__, __d__, __dlen__); \ + } else { \ + __res__ = -1; \ + } \ + __res__; \ }) /*! |