[asterisk-commits] coreyfarrell: trunk r427388 - in /trunk: ./ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Nov 6 03:18:52 CST 2014
Author: coreyfarrell
Date: Thu Nov 6 03:18:48 2014
New Revision: 427388
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=427388
Log:
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
........
Merged revisions 427384 from http://svn.asterisk.org/svn/asterisk/branches/13
Modified:
trunk/ (props changed)
trunk/include/asterisk/stringfields.h
trunk/main/utils.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.
Modified: trunk/include/asterisk/stringfields.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stringfields.h?view=diff&rev=427388&r1=427387&r2=427388
==============================================================================
--- trunk/include/asterisk/stringfields.h (original)
+++ trunk/include/asterisk/stringfields.h Thu Nov 6 03:18:48 2014
@@ -316,26 +316,28 @@
*/
#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__; \
})
/*!
Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=427388&r1=427387&r2=427388
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Thu Nov 6 03:18:48 2014
@@ -2099,9 +2099,13 @@
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;
}
@@ -2148,6 +2152,11 @@
if (res < 0) {
/* 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 */
More information about the asterisk-commits
mailing list