<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8517">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stringfields: Remove MALLOC_DEBUG fields from struct ast_string_field_mgr.<br><br>This causes MALLOC_DEBUG reporting to be slightly different, calls which<br>cause additional memory pools to be allocated now report the callers<br>location rather than the location which originally allocated the<br>string field structure. This reduces storage needed by string fields<br>and allows MALLOC_DEBUG to identify the source of additional allocations<br>rather than obscuring it by reporting the original allocation caller.<br><br>Change-Id: Idd18e6639a87ab862079b580c114d90361412289<br>---<br>M include/asterisk/stringfields.h<br>M main/stringfields.c<br>2 files changed, 39 insertions(+), 39 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/8517/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h<br>index 5ac5e09..edafb22 100644<br>--- a/include/asterisk/stringfields.h<br>+++ b/include/asterisk/stringfields.h<br>@@ -228,11 +228,6 @@<br> ast_string_field last_alloc; /*!< the last field allocated */<br> struct ast_string_field_pool *embedded_pool; /*!< pointer to the embedded pool, if any */<br> struct ast_string_field_vector string_fields; /*!< field vector for compare and copy */<br>- /* v-- MALLOC_DEBUG information */<br>- const char *owner_file; /*!< filename of owner */<br>- const char *owner_func; /*!< function name of owner */<br>- int owner_line; /*!< line number of owner */<br>- /* ^-- MALLOC_DEBUG information */<br> };<br> <br> /*!<br>@@ -266,7 +261,8 @@<br> an additional pool will be allocated.<br> */<br> ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,<br>- struct ast_string_field_pool **pool_head, size_t needed);<br>+ struct ast_string_field_pool **pool_head, size_t needed,<br>+ const char *file, int lineno, const char *func);<br> <br> /*!<br> \internal<br>@@ -277,9 +273,9 @@<br> \param format printf-style format string<br> \return nothing<br> */<br>-void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,<br>- struct ast_string_field_pool **pool_head,<br>- ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 4, 5)));<br>+void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,<br>+ struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head,<br>+ ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 7, 8)));<br> <br> /*!<br> \internal<br>@@ -292,8 +288,9 @@<br> \return nothing<br> */<br> void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,<br>- struct ast_string_field_pool **pool_head,<br>- ast_string_field *ptr, const char *format, va_list ap) __attribute__((format(printf, 4, 0)));<br>+ struct ast_string_field_pool **pool_head,<br>+ ast_string_field *ptr, const char *format, va_list ap,<br>+ const char *file, int lineno, const char *func) __attribute__((format(printf, 4, 0)));<br> <br> /*!<br> \brief Declare a string field<br>@@ -479,7 +476,7 @@<br> __res__; \<br> })<br> <br>-#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \<br>+#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func) \<br> ({ \<br> int __res__ = 0; \<br> const char *__d__ = (data); \<br>@@ -491,7 +488,7 @@<br> *__p__ = __ast_string_field_empty; \<br> } else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \<br> (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \<br>- (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__))) { \<br>+ (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__, file, lineno, func))) { \<br> if (target != *__p__) { \<br> __ast_string_field_release_active(field_mgr_pool, *__p__); \<br> *__p__ = target; \<br>@@ -502,6 +499,9 @@<br> } \<br> __res__; \<br> })<br>+<br>+#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \<br>+ __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> \brief Set a field to a simple string value<br>@@ -532,7 +532,8 @@<br> ({ \<br> int __res__ = -1; \<br> if (((void *)(x)) != NULL) { \<br>- __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \<br>+ __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \<br>+ &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \<br> __res__ = 0; \<br> } \<br> __res__; \<br>@@ -550,7 +551,8 @@<br> ({ \<br> int __res__ = -1; \<br> if (((void *)(x)) != NULL) { \<br>- __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \<br>+ __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \<br>+ &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \<br> __res__ = 0; \<br> } \<br> __res__; \<br>@@ -568,7 +570,8 @@<br> ({ \<br> int __res__ = -1; \<br> if (((void *)(x)) != NULL) { \<br>- __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \<br>+ __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args, \<br>+ __FILE__, __LINE__, __PRETTY_FUNCTION__); \<br> __res__ = 0; \<br> } \<br> __res__; \<br>@@ -586,7 +589,8 @@<br> ({ \<br> int __res__ = -1; \<br> if (((void *)(x)) != NULL) { \<br>- __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \<br>+ __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args, \<br>+ __FILE__, __LINE__, __PRETTY_FUNCTION__); \<br> __res__ = 0; \<br> } \<br> __res__; \<br>@@ -626,12 +630,14 @@<br> if (((void *)(copy)) != NULL && ((void *)(orig)) != NULL) { \<br> __res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \<br> (struct ast_string_field_mgr *)&((copy)->__field_mgr), \<br>- (struct ast_string_field_mgr *)&((orig)->__field_mgr)); \<br>+ (struct ast_string_field_mgr *)&((orig)->__field_mgr), \<br>+ __FILE__, __LINE__, __PRETTY_FUNCTION__); \<br> } \<br> __res__; \<br> })<br> <br> int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,<br>- struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr);<br>+ struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,<br>+ const char *file, int lineno, const char *func);<br> <br> #endif /* _ASTERISK_STRINGFIELDS_H */<br>diff --git a/main/stringfields.c b/main/stringfields.c<br>index 30aa8cd..0a9e599 100644<br>--- a/main/stringfields.c<br>+++ b/main/stringfields.c<br>@@ -179,11 +179,6 @@<br> }<br> <br> mgr->last_alloc = NULL;<br>- /* v-- MALLOC_DEBUG information */<br>- mgr->owner_file = file;<br>- mgr->owner_func = func;<br>- mgr->owner_line = lineno;<br>- /* ^-- MALLOC_DEBUG information */<br> <br> if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {<br> return -1;<br>@@ -205,7 +200,8 @@<br> }<br> <br> ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,<br>- struct ast_string_field_pool **pool_head, size_t needed)<br>+ struct ast_string_field_pool **pool_head, size_t needed,<br>+ const char *file, int lineno, const char *func)<br> {<br> char *result = NULL;<br> size_t space = (*pool_head)->size - (*pool_head)->used;<br>@@ -222,8 +218,7 @@<br> new_size *= 2;<br> }<br> <br>- if (add_string_pool(mgr, pool_head, new_size,<br>- mgr->owner_file, mgr->owner_line, mgr->owner_func)) {<br>+ if (add_string_pool(mgr, pool_head, new_size, file, lineno, func)) {<br> return NULL;<br> }<br> }<br>@@ -290,7 +285,8 @@<br> <br> void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,<br> struct ast_string_field_pool **pool_head, ast_string_field *ptr,<br>- const char *format, va_list ap)<br>+ const char *format, va_list ap,<br>+ const char *file, int lineno, const char *func)<br> {<br> size_t needed;<br> size_t available;<br>@@ -342,7 +338,8 @@<br> (if it has one), or the space available in the pool (if it does not). allocate<br> space for it, adding a new string pool if necessary.<br> */<br>- if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) {<br>+ target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed, file, lineno, func);<br>+ if (!target) {<br> return;<br> }<br> vsprintf(target, format, ap);<br>@@ -369,13 +366,14 @@<br> }<br> }<br> <br>-void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,<br>+void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,<br>+ struct ast_string_field_mgr *mgr,<br> struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, ...)<br> {<br> va_list ap;<br> <br> va_start(ap, format);<br>- __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap);<br>+ __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap, file, lineno, func);<br> va_end(ap);<br> }<br> <br>@@ -419,11 +417,6 @@<br> mgr->embedded_pool = pool;<br> *pool_head = pool;<br> pool->size = size_to_alloc - struct_size - sizeof(*pool);<br>- /* v-- MALLOC_DEBUG information */<br>- mgr->owner_file = file;<br>- mgr->owner_func = func;<br>- mgr->owner_line = lineno;<br>- /* ^-- MALLOC_DEBUG information */<br> <br> return allocation;<br> }<br>@@ -446,7 +439,8 @@<br> }<br> <br> int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,<br>- struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr)<br>+ struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,<br>+ const char *file, int lineno, const char *func)<br> {<br> int i;<br> struct ast_string_field_vector *dest = &(copy_mgr->string_fields);<br>@@ -460,8 +454,8 @@<br> }<br> <br> for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {<br>- if (ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),<br>- *AST_VECTOR_GET(src, i))) {<br>+ if (__ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),<br>+ *AST_VECTOR_GET(src, i), file, lineno, func)) {<br> return -1;<br> }<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8517">change 8517</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8517"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Idd18e6639a87ab862079b580c114d90361412289 </div>
<div style="display:none"> Gerrit-Change-Number: 8517 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>