<p>Richard Mudgett has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8366">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">MALLOC_DEBUG: Always use the API.<br><br>Always use the MALLOC_DEBUG API so pre-compiled modules will still work<br>regardless of MALLOC_DEBUG being enabled or not.<br><br>Change-Id: Ic07ad80b2c2df894db984cf27b16a69383ce0e10<br>---<br>M include/asterisk.h<br>M include/asterisk/astmm.h<br>M include/asterisk/chanvars.h<br>M include/asterisk/compat.h<br>M include/asterisk/config.h<br>M include/asterisk/hashtab.h<br>M include/asterisk/heap.h<br>M include/asterisk/stringfields.h<br>M include/asterisk/strings.h<br>M include/asterisk/utils.h<br>M main/astmm.c<br>M main/chanvars.c<br>M main/config.c<br>M main/datastore.c<br>M main/hashtab.c<br>M main/heap.c<br>M main/strcompat.c<br>M main/stringfields.c<br>M main/strings.c<br>M main/utils.c<br>M menuselect/strcompat.c<br>M res/stasis_recording/stored.c<br>M third-party/pjproject/patches/asterisk_malloc_debug.c<br>M third-party/pjproject/patches/asterisk_malloc_debug.h<br>24 files changed, 362 insertions(+), 473 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/8366/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk.h b/include/asterisk.h<br>index 3718602..27d66b7 100644<br>--- a/include/asterisk.h<br>+++ b/include/asterisk.h<br>@@ -21,7 +21,7 @@<br> #include "asterisk/autoconfig.h"<br> #include "asterisk/compat.h"<br> <br>-#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)<br>+#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)<br> #include "asterisk/astmm.h"<br> #endif<br> <br>diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h<br>index 06300c8..4e4a65b 100644<br>--- a/include/asterisk/astmm.h<br>+++ b/include/asterisk/astmm.h<br>@@ -32,7 +32,12 @@<br> #define _ASTERISK_ASTMM_H<br> /* IWYU pragma: private, include "asterisk.h" */<br> <br>+#if defined(MALLOC_DEBUG)<br> #define __AST_DEBUG_MALLOC<br>+<br>+void __ast_mm_init_phase_1(void);<br>+void __ast_mm_init_phase_2(void);<br>+#endif<br> <br> void *ast_std_malloc(size_t size);<br> void *ast_std_calloc(size_t nmemb, size_t size);<br>@@ -40,19 +45,17 @@<br> void ast_std_free(void *ptr);<br> void ast_free_ptr(void *ptr);<br> <br>-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>-void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func);<br> void __ast_free(void *ptr, const char *file, int lineno, const char *func);<br>-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);<br>-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);<br>-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);<br>-int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);<br>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func);<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);<br>+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br> __attribute__((format(printf, 5, 6)));<br>-int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br> __attribute__((format(printf, 2, 0)));<br>-void __ast_mm_init_phase_1(void);<br>-void __ast_mm_init_phase_2(void);<br> <br> /*!<br> * \brief ASTMM_LIBC can be defined to control the meaning of standard allocators.<br>@@ -120,42 +123,42 @@<br> #if ASTMM_LIBC == ASTMM_REDIRECT<br> <br> /* Redefine libc functions to our own versions */<br>-#define calloc(a,b) \<br>- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define calloc(a, b) \<br>+ __ast_repl_calloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define malloc(a) \<br>- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_malloc(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define free(a) \<br>- __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#define realloc(a,b) \<br>- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define realloc(a, b) \<br>+ __ast_repl_realloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define strdup(a) \<br>- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#define strndup(a,b) \<br>- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_strdup(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define strndup(a, b) \<br>+ __ast_repl_strndup(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define asprintf(a, b, c...) \<br>- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>-#define vasprintf(a,b,c) \<br>- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>+#define vasprintf(a, b, c) \<br>+ __ast_repl_vasprintf(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #elif ASTMM_LIBC == ASTMM_BLOCK<br> <br> /* Redefine libc functions to cause compile errors */<br>-#define calloc(a,b) \<br>- Do_not_use_calloc__use_ast_calloc->fail(a,b)<br>+#define calloc(a, b) \<br>+ Do_not_use_calloc__use_ast_calloc->fail(a, b)<br> #define malloc(a) \<br> Do_not_use_malloc__use_ast_malloc->fail(a)<br> #define free(a) \<br> Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory->fail(a)<br>-#define realloc(a,b) \<br>- Do_not_use_realloc__use_ast_realloc->fail(a,b)<br>+#define realloc(a, b) \<br>+ Do_not_use_realloc__use_ast_realloc->fail(a, b)<br> #define strdup(a) \<br> Do_not_use_strdup__use_ast_strdup->fail(a)<br>-#define strndup(a,b) \<br>- Do_not_use_strndup__use_ast_strndup->fail(a,b)<br>+#define strndup(a, b) \<br>+ Do_not_use_strndup__use_ast_strndup->fail(a, b)<br> #define asprintf(a, b, c...) \<br>- Do_not_use_asprintf__use_ast_asprintf->fail(a,b,c)<br>-#define vasprintf(a,b,c) \<br>- Do_not_use_vasprintf__use_ast_vasprintf->fail(a,b,c)<br>+ Do_not_use_asprintf__use_ast_asprintf->fail(a, b, c)<br>+#define vasprintf(a, b, c) \<br>+ Do_not_use_vasprintf__use_ast_vasprintf->fail(a, b, c)<br> <br> #else<br> #error "Unacceptable value for the macro ASTMM_LIBC"<br>@@ -166,7 +169,7 @@<br> /* Provide our own definition for ast_free */<br> <br> #define ast_free(a) \<br>- __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #else<br> #error "NEVER INCLUDE astmm.h DIRECTLY!!"<br>diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h<br>index 2040c7b..1a303c5 100644<br>--- a/include/asterisk/chanvars.h<br>+++ b/include/asterisk/chanvars.h<br>@@ -35,12 +35,10 @@<br> <br> struct varshead *ast_var_list_create(void);<br> void ast_var_list_destroy(struct varshead *head);<br>-#ifdef __AST_DEBUG_MALLOC<br>+<br> struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function);<br>-#define ast_var_assign(a,b) _ast_var_assign(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_var_t *ast_var_assign(const char *name, const char *value);<br>-#endif<br>+#define ast_var_assign(name, value) _ast_var_assign(name, value, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br> void ast_var_delete(struct ast_var_t *var);<br> const char *ast_var_name(const struct ast_var_t *var);<br> const char *ast_var_full_name(const struct ast_var_t *var);<br>diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h<br>index 2e89a39..8547283 100644<br>--- a/include/asterisk/compat.h<br>+++ b/include/asterisk/compat.h<br>@@ -64,7 +64,7 @@<br> void closefrom(int lowfd);<br> #endif<br> <br>-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_ASPRINTF)<br> int __attribute__((format(printf, 2, 3))) asprintf(char **str, const char *fmt, ...);<br> #endif<br> <br>@@ -96,7 +96,7 @@<br> char *strcasestr(const char *, const char *);<br> #endif<br> <br>-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_STRNDUP)<br> char *strndup(const char *, size_t);<br> #endif<br> <br>@@ -116,7 +116,7 @@<br> int unsetenv(const char *name);<br> #endif<br> <br>-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_VASPRINTF)<br> int __attribute__((format(printf, 2, 0))) vasprintf(char **strp, const char *fmt, va_list ap);<br> #endif<br> <br>diff --git a/include/asterisk/config.h b/include/asterisk/config.h<br>index fd9641e..8912840 100644<br>--- a/include/asterisk/config.h<br>+++ b/include/asterisk/config.h<br>@@ -919,12 +919,9 @@<br> struct ast_variable *ast_category_detach_variables(struct ast_category *cat);<br> void ast_category_rename(struct ast_category *cat, const char *name);<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno);<br> #define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)<br>-#else<br>-struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename);<br>-#endif<br>+<br> struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size);<br> struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);<br> void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file);<br>diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h<br>index cfe035b..64ed1bf 100644<br>--- a/include/asterisk/hashtab.h<br>+++ b/include/asterisk/hashtab.h<br>@@ -251,22 +251,15 @@<br> * \param hash a func ptr to do the hashing<br> * \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br>-struct ast_hashtab * _ast_hashtab_create(int initial_buckets,<br>- int (*compare)(const void *a, const void *b),<br>- int (*resize)(struct ast_hashtab *),<br>- int (*newsize)(struct ast_hashtab *tab),<br>- unsigned int (*hash)(const void *obj),<br>- int do_locking, const char *file, int lineno, const char *function);<br>-#define ast_hashtab_create(a,b,c,d,e,f) _ast_hashtab_create(a,b,c,d,e,f,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_hashtab * ast_hashtab_create(int initial_buckets,<br>- int (*compare)(const void *a, const void *b),<br>- int (*resize)(struct ast_hashtab *),<br>- int (*newsize)(struct ast_hashtab *tab),<br>- unsigned int (*hash)(const void *obj),<br>- int do_locking );<br>-#endif<br>+struct ast_hashtab *_ast_hashtab_create(int initial_buckets,<br>+ int (*compare)(const void *a, const void *b),<br>+ int (*resize)(struct ast_hashtab *),<br>+ int (*newsize)(struct ast_hashtab *tab),<br>+ unsigned int (*hash)(const void *obj),<br>+ int do_locking,<br>+ const char *file, int lineno, const char *function);<br>+#define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking) \<br>+ _ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief This func will free the hash table and all its memory.<br>@@ -294,12 +287,9 @@<br> * \retval 1 on success<br> * \retval 0 if there's a problem<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_insert_immediate(a,b) _ast_hashtab_insert_immediate(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#else<br>-int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj);<br>-#endif<br>+#define ast_hashtab_insert_immediate(tab, obj) \<br>+ _ast_hashtab_insert_immediate(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Insert without checking, hashing or locking<br>@@ -311,12 +301,9 @@<br> * \retval 1 on success<br> * \retval 0 if there's a problem<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_insert_immediate_bucket(a,b,c) _ast_hashtab_insert_immediate_bucket(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#else<br>-int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h);<br>-#endif<br>+#define ast_hashtab_insert_immediate_bucket(tab, obj, h) \<br>+ _ast_hashtab_insert_immediate_bucket(tab, obj, h, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Check and insert new object only if it is not there.<br>@@ -324,12 +311,9 @@<br> * \retval 1 on success<br> * \retval 0 if there's a problem, or it's already there.<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_insert_safe(a,b) _ast_hashtab_insert_safe(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#else<br>-int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj);<br>-#endif<br>+#define ast_hashtab_insert_safe(tab, obj) \<br>+ _ast_hashtab_insert_safe(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Lookup this object in the hash table.<br>@@ -362,20 +346,14 @@<br> int ast_hashtab_capacity( struct ast_hashtab *tab);<br> <br> /*! \brief Return a copy of the hash table */<br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func);<br>-#define ast_hashtab_dup(a,b) _ast_hashtab_dup(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj));<br>-#endif<br>+#define ast_hashtab_dup(tab, obj_dup_func) \<br>+ _ast_hashtab_dup(tab, obj_dup_func, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*! \brief Gives an iterator to hastable */<br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_start_traversal(a) _ast_hashtab_start_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab);<br>-#endif<br>+#define ast_hashtab_start_traversal(tab) \<br>+ _ast_hashtab_start_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*! \brief end the traversal, free the iterator, unlock if necc. */<br> void ast_hashtab_end_traversal(struct ast_hashtab_iter *it);<br>@@ -395,12 +373,9 @@<br> /* ------------------ */<br> <br> /*! \brief Gives an iterator to hastable */<br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_start_write_traversal(a) _ast_hashtab_start_write_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_hashtab_iter *ast_hashtab_start_write_traversal(struct ast_hashtab *tab);<br>-#endif<br>+#define ast_hashtab_start_write_traversal(tab) \<br>+ _ast_hashtab_start_write_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*! \brief Looks up the object, removes the corresponding bucket */<br> void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj);<br>diff --git a/include/asterisk/heap.h b/include/asterisk/heap.h<br>index 7283279..83c69a8 100644<br>--- a/include/asterisk/heap.h<br>+++ b/include/asterisk/heap.h<br>@@ -97,14 +97,10 @@<br> * \return An instance of a max heap<br> * \since 1.6.1<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,<br> ssize_t index_offset, const char *file, int lineno, const char *func);<br>-#define ast_heap_create(a,b,c) _ast_heap_create(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,<br>- ssize_t index_offset);<br>-#endif<br>+#define ast_heap_create(init_height, cmp_fn, index_offset) \<br>+ _ast_heap_create(init_height, cmp_fn, index_offset, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Destroy a max heap<br>@@ -126,12 +122,9 @@<br> * \retval non-zero failure<br> * \since 1.6.1<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func);<br>-#define ast_heap_push(a,b) _ast_heap_push(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-int ast_heap_push(struct ast_heap *h, void *elm);<br>-#endif<br>+#define ast_heap_push(h, elm) \<br>+ _ast_heap_push(h, elm, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Pop the max element off of the heap<br>diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h<br>index 69f2fcc..5ac5e09 100644<br>--- a/include/asterisk/stringfields.h<br>+++ b/include/asterisk/stringfields.h<br>@@ -228,11 +228,11 @@<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>-#if defined(__AST_DEBUG_MALLOC)<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>-#endif<br>+ /* ^-- MALLOC_DEBUG information */<br> };<br> <br> /*!<br>diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h<br>index 85393b4..e4bef5f 100644<br>--- a/include/asterisk/strings.h<br>+++ b/include/asterisk/strings.h<br>@@ -617,8 +617,8 @@<br> * \note The result of this function is dynamically allocated memory, and must<br> * be free()'d after it is no longer needed.<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br>-#define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>+#define ast_str_create(init_len) \<br>+ _ast_str_create(init_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> AST_INLINE_API(<br> struct ast_str * attribute_malloc _ast_str_create(size_t init_len,<br> const char *file, int lineno, const char *func),<br>@@ -636,24 +636,6 @@<br> return buf;<br> }<br> )<br>-#else<br>-AST_INLINE_API(<br>-struct ast_str * attribute_malloc ast_str_create(size_t init_len),<br>-{<br>- struct ast_str *buf;<br>-<br>- buf = (struct ast_str *)ast_calloc(1, sizeof(*buf) + init_len);<br>- if (buf == NULL)<br>- return NULL;<br>-<br>- buf->__AST_STR_LEN = init_len;<br>- buf->__AST_STR_USED = 0;<br>- buf->__AST_STR_TS = DS_MALLOC;<br>-<br>- return buf;<br>-}<br>-)<br>-#endif<br> <br> /*! \brief Reset the content of a dynamic string.<br> * Useful before a series of ast_str_append.<br>@@ -772,7 +754,6 @@<br> /*!<br> * Make space in a new string (e.g. to read in data from a file)<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br> AST_INLINE_API(<br> int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function),<br> {<br>@@ -796,32 +777,8 @@<br> return 0;<br> }<br> )<br>-#define ast_str_make_space(a,b) _ast_str_make_space(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-AST_INLINE_API(<br>-int ast_str_make_space(struct ast_str **buf, size_t new_len),<br>-{<br>- struct ast_str *old_buf = *buf;<br>-<br>- if (new_len <= (*buf)->__AST_STR_LEN)<br>- return 0; /* success */<br>- if ((*buf)->__AST_STR_TS == DS_ALLOCA || (*buf)->__AST_STR_TS == DS_STATIC)<br>- return -1; /* cannot extend */<br>- *buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));<br>- if (*buf == NULL) {<br>- *buf = old_buf;<br>- return -1;<br>- }<br>- if ((*buf)->__AST_STR_TS != DS_MALLOC) {<br>- pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);<br>- _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)<br>- }<br>-<br>- (*buf)->__AST_STR_LEN = new_len;<br>- return 0;<br>-}<br>-)<br>-#endif<br>+#define ast_str_make_space(buf, new_len) \<br>+ _ast_str_make_space(buf, new_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> AST_INLINE_API(<br> int ast_str_copy_string(struct ast_str **dst, struct ast_str *src),<br>@@ -965,14 +922,12 @@<br> * through calling one of the other functions or macros defined in this<br> * file.<br> */<br>-#ifdef __AST_DEBUG_MALLOC<br>-int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,<br>- int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func);<br>-#define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)<br>-#else<br>-int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, ssize_t max_len,<br>- int append, const char *fmt, va_list ap);<br>-#endif<br>+int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf,<br>+ ssize_t max_len, int append, const char *fmt, va_list ap,<br>+ const char *file, int lineno, const char *func);<br>+#define _ast_str_helper(buf, max_len, append, fmt, ap) \<br>+ __ast_str_helper(buf, max_len, append, fmt, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br> char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,<br> const char *src, size_t maxsrc, int append, int escapecommas);<br> <br>@@ -1022,7 +977,7 @@<br> */<br> AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),<br> {<br>- return __ast_str_helper(buf, max_len, 0, fmt, ap);<br>+ return _ast_str_helper(buf, max_len, 0, fmt, ap);<br> }<br> )<br> <br>@@ -1040,7 +995,7 @@<br> */<br> AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),<br> {<br>- return __ast_str_helper(buf, max_len, 1, fmt, ap);<br>+ return _ast_str_helper(buf, max_len, 1, fmt, ap);<br> }<br> )<br> <br>diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h<br>index c6c3407..a9e707b 100644<br>--- a/include/asterisk/utils.h<br>+++ b/include/asterisk/utils.h<br>@@ -509,11 +509,11 @@<br> #endif<br> <br> <br>-#ifndef __AST_DEBUG_MALLOC<br>-#define ast_std_malloc malloc<br>-#define ast_std_calloc calloc<br>-#define ast_std_realloc realloc<br>-#define ast_std_free free<br>+#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)<br>+void *ast_std_malloc(size_t size);<br>+void *ast_std_calloc(size_t nmemb, size_t size);<br>+void *ast_std_realloc(void *ptr, size_t size);<br>+void ast_std_free(void *ptr);<br> <br> /*!<br> * \brief free() wrapper<br>@@ -521,8 +521,42 @@<br> * ast_free_ptr should be used when a function pointer for free() needs to be passed<br> * as the argument to a function. Otherwise, astmm will cause seg faults.<br> */<br>+void ast_free_ptr(void *ptr);<br>+void __ast_free(void *ptr, const char *file, int lineno, const char *func);<br>+<br>+#else<br>+<br>+/* Need to defeat the MALLOC_DEBUG API when building the standalone utilities. */<br>+#define ast_std_malloc malloc<br>+#define ast_std_calloc calloc<br>+#define ast_std_realloc realloc<br>+#define ast_std_free free<br>+<br>+#define ast_free_ptr free<br> #define ast_free free<br>-#define ast_free_ptr ast_free<br>+<br>+#define __ast_repl_calloc(nmemb, size, file, lineno, func) \<br>+ calloc(nmemb, size)<br>+<br>+#define __ast_repl_calloc_cache(nmemb, size, file, lineno, func) \<br>+ calloc(nmemb, size)<br>+<br>+#define __ast_repl_malloc(size, file, lineno, func) \<br>+ malloc(size)<br>+<br>+#define __ast_repl_realloc(ptr, size, file, lineno, func) \<br>+ realloc(ptr, size)<br>+<br>+#define __ast_repl_strdup(s, file, lineno, func) \<br>+ strdup(s)<br>+<br>+#define __ast_repl_strndup(s, n, file, lineno, func) \<br>+ strndup(s, n)<br>+<br>+#define __ast_repl_vasprintf(strp, format, ap, file, lineno, func) \<br>+ vasprintf(strp, format, ap)<br>+<br>+#endif<br> <br> #if defined(AST_IN_CORE)<br> #define MALLOC_FAILURE_MSG \<br>@@ -539,7 +573,8 @@<br> <br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br>- if (!(p = malloc(len))) {<br>+ p = __ast_repl_malloc(len, file, lineno, func);<br>+ if (!p) {<br> MALLOC_FAILURE_MSG;<br> }<br> <br>@@ -554,7 +589,24 @@<br> <br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br>- if (!(p = calloc(num, len))) {<br>+ p = __ast_repl_calloc(num, len, file, lineno, func);<br>+ if (!p) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return p;<br>+}<br>+)<br>+<br>+AST_INLINE_API(<br>+void * attribute_malloc __ast_calloc_cache(size_t num, size_t len, const char *file, int lineno, const char *func),<br>+{<br>+ void *p;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ p = __ast_repl_calloc_cache(num, len, file, lineno, func);<br>+ if (!p) {<br> MALLOC_FAILURE_MSG;<br> }<br> <br>@@ -569,7 +621,8 @@<br> <br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br>- if (!(newp = realloc(p, len))) {<br>+ newp = __ast_repl_realloc(p, len, file, lineno, func);<br>+ if (!newp) {<br> MALLOC_FAILURE_MSG;<br> }<br> <br>@@ -585,7 +638,8 @@<br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br> if (str) {<br>- if (!(newstr = strdup(str))) {<br>+ newstr = __ast_repl_strdup(str, file, lineno, func);<br>+ if (!newstr) {<br> MALLOC_FAILURE_MSG;<br> }<br> }<br>@@ -602,7 +656,8 @@<br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br> if (str) {<br>- if (!(newstr = strndup(str, len))) {<br>+ newstr = __ast_repl_strndup(str, len, file, lineno, func);<br>+ if (!newstr) {<br> MALLOC_FAILURE_MSG;<br> }<br> }<br>@@ -611,8 +666,30 @@<br> }<br> )<br> <br>-int __attribute__((format(printf, 5, 6)))<br>- __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...);<br>+AST_INLINE_API(<br>+__attribute__((format(printf, 5, 6)))<br>+int __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...),<br>+{<br>+ int res;<br>+ va_list ap;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br>+<br>+ va_start(ap, fmt);<br>+ res = __ast_repl_vasprintf(ret, fmt, ap, file, lineno, func);<br>+ if (res < 0) {<br>+ /*<br>+ * *ret is undefined so set to NULL to ensure it is<br>+ * initialized to something useful.<br>+ */<br>+ *ret = NULL;<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+ va_end(ap);<br>+<br>+ return res;<br>+}<br>+)<br> <br> AST_INLINE_API(<br> __attribute__((format(printf, 2, 0)))<br>@@ -622,7 +699,7 @@<br> <br> DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br> <br>- res = vasprintf(ret, fmt, ap);<br>+ res = __ast_repl_vasprintf(ret, fmt, ap, file, lineno, func);<br> if (res < 0) {<br> /*<br> * *ret is undefined so set to NULL to ensure it is<br>@@ -635,8 +712,6 @@<br> return res;<br> }<br> )<br>-<br>-#endif /* AST_DEBUG_MALLOC */<br> <br> /*!<br> * \brief A wrapper for malloc()<br>@@ -671,7 +746,7 @@<br> * The arguments and return value are the same as calloc()<br> */<br> #define ast_calloc_cache(num, len) \<br>- __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_calloc_cache((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief A wrapper for realloc()<br>diff --git a/main/astmm.c b/main/astmm.c<br>index accd2ff..1fa35d7 100644<br>--- a/main/astmm.c<br>+++ b/main/astmm.c<br>@@ -149,31 +149,6 @@<br> } \<br> } while (0)<br> <br>-void *ast_std_malloc(size_t size)<br>-{<br>- return malloc(size);<br>-}<br>-<br>-void *ast_std_calloc(size_t nmemb, size_t size)<br>-{<br>- return calloc(nmemb, size);<br>-}<br>-<br>-void *ast_std_realloc(void *ptr, size_t size)<br>-{<br>- return realloc(ptr, size);<br>-}<br>-<br>-void ast_std_free(void *ptr)<br>-{<br>- free(ptr);<br>-}<br>-<br>-void ast_free_ptr(void *ptr)<br>-{<br>- ast_free(ptr);<br>-}<br>-<br> static void print_backtrace(struct ast_bt *bt)<br> {<br> int i = 0;<br>@@ -479,7 +454,7 @@<br> }<br> }<br> <br>-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br> void *ptr;<br> <br>@@ -491,7 +466,7 @@<br> return ptr;<br> }<br> <br>-void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br> void *ptr;<br> <br>@@ -503,7 +478,7 @@<br> return ptr;<br> }<br> <br>-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)<br> {<br> void *ptr;<br> <br>@@ -539,7 +514,7 @@<br> return reg;<br> }<br> <br>-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br> {<br> size_t len;<br> struct ast_region *found;<br>@@ -588,7 +563,7 @@<br> return new_mem;<br> }<br> <br>-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)<br>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br> {<br> size_t len;<br> void *ptr;<br>@@ -603,7 +578,7 @@<br> return ptr;<br> }<br> <br>-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br> {<br> size_t len;<br> char *ptr;<br>@@ -621,7 +596,7 @@<br> return ptr;<br> }<br> <br>-int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)<br>+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)<br> {<br> int size;<br> va_list ap, ap2;<br>@@ -642,7 +617,7 @@<br> return size;<br> }<br> <br>-int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)<br>+int __ast_repl_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)<br> {<br> int size;<br> va_list ap2;<br>@@ -1543,4 +1518,83 @@<br> ast_register_cleanup(mm_atexit_ast);<br> }<br> <br>+#else /* !defined(__AST_DEBUG_MALLOC) */<br>+<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+ return calloc(nmemb, size);<br>+}<br>+<br>+void *__ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+ return calloc(nmemb, size);<br>+}<br>+<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)<br>+{<br>+ return malloc(size);<br>+}<br>+<br>+void __ast_free(void *ptr, const char *file, int lineno, const char *func)<br>+{<br>+ free(ptr);<br>+}<br>+<br>+void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+ return realloc(ptr, size);<br>+}<br>+<br>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br>+{<br>+ return strdup(s);<br>+}<br>+<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br>+{<br>+ return strndup(s, n);<br>+}<br>+<br>+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+{<br>+ va_list ap;<br>+ int rc = 0;<br>+<br>+ va_start(ap, format);<br>+ rc = vasprintf(strp, format, ap);<br>+ va_end(ap);<br>+<br>+ return rc;<br>+}<br>+<br>+int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+{<br>+ return vasprintf(strp, format, ap);<br>+}<br>+<br> #endif /* defined(__AST_DEBUG_MALLOC) */<br>+<br>+void *ast_std_malloc(size_t size)<br>+{<br>+ return malloc(size);<br>+}<br>+<br>+void *ast_std_calloc(size_t nmemb, size_t size)<br>+{<br>+ return calloc(nmemb, size);<br>+}<br>+<br>+void *ast_std_realloc(void *ptr, size_t size)<br>+{<br>+ return realloc(ptr, size);<br>+}<br>+<br>+void ast_std_free(void *ptr)<br>+{<br>+ free(ptr);<br>+}<br>+<br>+void ast_free_ptr(void *ptr)<br>+{<br>+ ast_free(ptr);<br>+}<br>diff --git a/main/chanvars.c b/main/chanvars.c<br>index 2cc90e4..0802646 100644<br>--- a/main/chanvars.c<br>+++ b/main/chanvars.c<br>@@ -33,21 +33,15 @@<br> #include "asterisk/strings.h"<br> #include "asterisk/utils.h"<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)<br>-#else<br>-struct ast_var_t *ast_var_assign(const char *name, const char *value)<br>-#endif<br> {<br> struct ast_var_t *var;<br> int name_len = strlen(name) + 1;<br> int value_len = strlen(value) + 1;<br> <br>-#ifdef __AST_DEBUG_MALLOC<br>- if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {<br>-#else<br>- if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {<br>-#endif<br>+ var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char),<br>+ file, lineno, function);<br>+ if (!var) {<br> return NULL;<br> }<br> <br>diff --git a/main/config.c b/main/config.c<br>index 118b958..27a61c2 100644<br>--- a/main/config.c<br>+++ b/main/config.c<br>@@ -281,11 +281,7 @@<br> static void ast_variable_destroy(struct ast_variable *doomed);<br> static void ast_includes_destroy(struct ast_config_include *incls);<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *func, int lineno)<br>-#else<br>-struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename)<br>-#endif<br> {<br> struct ast_variable *variable;<br> int name_len = strlen(name) + 1;<br>@@ -297,13 +293,9 @@<br> fn_len = MIN_VARIABLE_FNAME_SPACE;<br> }<br> <br>- if (<br>-#ifdef __AST_DEBUG_MALLOC<br>- (variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable), file, lineno, func))<br>-#else<br>- (variable = ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable)))<br>-#endif<br>- ) {<br>+ variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable),<br>+ file, lineno, func);<br>+ if (variable) {<br> char *dst = variable->stuff; /* writable space starts here */<br> <br> /* Put file first so ast_include_rename() can calculate space available. */<br>diff --git a/main/datastore.c b/main/datastore.c<br>index a12bbdf..5edad24 100644<br>--- a/main/datastore.c<br>+++ b/main/datastore.c<br>@@ -47,7 +47,8 @@<br> return NULL;<br> }<br> <br>- if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) {<br>+ datastore = __ast_calloc(1, sizeof(*datastore), file, line, function);<br>+ if (!datastore) {<br> return NULL;<br> }<br> <br>diff --git a/main/hashtab.c b/main/hashtab.c<br>index eefe443..1f9c7bf 100644<br>--- a/main/hashtab.c<br>+++ b/main/hashtab.c<br>@@ -41,12 +41,10 @@<br> #include "asterisk/hashtab.h"<br> <br> <br>-#ifdef __AST_DEBUG_MALLOC<br> static void _ast_hashtab_resize(struct ast_hashtab *tab, const char *file, int lineno, const char *func);<br>-#define ast_hashtab_resize(a) _ast_hashtab_resize(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#else<br>-static void ast_hashtab_resize(struct ast_hashtab *tab);<br>-#endif<br>+#define ast_hashtab_resize(tab) \<br>+ _ast_hashtab_resize(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br> static void *ast_hashtab_lookup_internal(struct ast_hashtab *tab, const void *obj, unsigned int h);<br> <br> /* some standard, default routines for general use */<br>@@ -215,40 +213,28 @@<br> return x;<br> }<br> <br>-struct ast_hashtab *<br>-#ifdef __AST_DEBUG_MALLOC<br>-_ast_hashtab_create<br>-#else<br>-ast_hashtab_create<br>-#endif<br>-(int initial_buckets,<br>+struct ast_hashtab *_ast_hashtab_create(int initial_buckets,<br> int (*compare)(const void *a, const void *b),<br> int (*resize)(struct ast_hashtab *),<br> int (*newsize)(struct ast_hashtab *tab),<br> unsigned int (*hash)(const void *obj),<br>- int do_locking<br>-#ifdef __AST_DEBUG_MALLOC<br>- , const char *file, int lineno, const char *function<br>-#endif<br>+ int do_locking,<br>+ const char *file, int lineno, const char *function<br> )<br> {<br> struct ast_hashtab *ht;<br> <br>-#ifdef __AST_DEBUG_MALLOC<br>- if (!(ht = __ast_calloc(1, sizeof(*ht), file, lineno, function)))<br>-#else<br>- if (!(ht = ast_calloc(1, sizeof(*ht))))<br>-#endif<br>+ ht = __ast_calloc(1, sizeof(*ht), file, lineno, function);<br>+ if (!ht) {<br> return NULL;<br>+ }<br> <br> while (!ast_is_prime(initial_buckets)) /* make sure this is prime */<br> initial_buckets++;<br> <br>-#ifdef __AST_DEBUG_MALLOC<br>- if (!(ht->array = __ast_calloc(initial_buckets, sizeof(*(ht->array)), file, lineno, function))) {<br>-#else<br>- if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) {<br>-#endif<br>+ ht->array = __ast_calloc(initial_buckets, sizeof(*(ht->array)),<br>+ file, lineno, function);<br>+ if (!ht->array) {<br> ast_free(ht);<br> return NULL;<br> }<br>@@ -272,25 +258,19 @@<br> return ht;<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func)<br>-#else<br>-struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj))<br>-#endif<br> {<br> struct ast_hashtab *ht;<br> unsigned int i;<br> <br>- if (!(ht = ast_calloc(1, sizeof(*ht))))<br>+ ht = __ast_calloc(1, sizeof(*ht), file, lineno, func);<br>+ if (!ht) {<br> return NULL;<br>+ }<br> <br>- if (!(ht->array =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)), file, lineno, func)<br>-#else<br>- ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)))<br>-#endif<br>- )) {<br>+ ht->array = __ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)),<br>+ file, lineno, func);<br>+ if (!ht->array) {<br> ast_free(ht);<br> return NULL;<br> }<br>@@ -312,12 +292,9 @@<br> struct ast_hashtab_bucket *b = tab->array[i];<br> while (b) {<br> void *newobj = (*obj_dup_func)(b->object);<br>- if (newobj)<br>-#ifdef __AST_DEBUG_MALLOC<br>+ if (newobj) {<br> _ast_hashtab_insert_immediate_bucket(ht, newobj, i, file, lineno, func);<br>-#else<br>- ast_hashtab_insert_immediate_bucket(ht, newobj, i);<br>-#endif<br>+ }<br> b = b->next;<br> }<br> }<br>@@ -424,11 +401,7 @@<br> }<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)<br>-#else<br>-int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)<br>-#endif<br> {<br> unsigned int h;<br> int res=0;<br>@@ -441,11 +414,7 @@<br> <br> h = (*tab->hash)(obj) % tab->hash_tab_size;<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> res = _ast_hashtab_insert_immediate_bucket(tab, obj, h, file, lineno, func);<br>-#else<br>- res = ast_hashtab_insert_immediate_bucket(tab, obj, h);<br>-#endif<br> <br> if (tab->do_locking)<br> ast_rwlock_unlock(&tab->lock);<br>@@ -453,11 +422,7 @@<br> return res;<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func)<br>-#else<br>-int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h)<br>-#endif<br> {<br> int c;<br> struct ast_hashtab_bucket *b;<br>@@ -471,13 +436,10 @@<br> if (c + 1 > tab->largest_bucket_size)<br> tab->largest_bucket_size = c + 1;<br> <br>- if (!(b =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(1, sizeof(*b), file, lineno, func)<br>-#else<br>- ast_calloc(1, sizeof(*b))<br>-#endif<br>- )) return 0;<br>+ b = __ast_calloc(1, sizeof(*b), file, lineno, func);<br>+ if (!b) {<br>+ return 0;<br>+ }<br> <br> b->object = obj;<br> b->next = tab->array[h];<br>@@ -495,11 +457,7 @@<br> return 1;<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)<br>-#else<br>-int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)<br>-#endif<br> {<br> /* check to see if the element is already there; insert only if<br> it is not there. */<br>@@ -511,11 +469,7 @@<br> ast_rwlock_wrlock(&tab->lock);<br> <br> if (!ast_hashtab_lookup_bucket(tab, obj, &bucket)) {<br>-#ifdef __AST_DEBUG_MALLOC<br> int ret2 = _ast_hashtab_insert_immediate_bucket(tab, obj, bucket, file, lineno, func);<br>-#else<br>- int ret2 = ast_hashtab_insert_immediate_bucket(tab, obj, bucket);<br>-#endif<br> <br> if (tab->do_locking)<br> ast_rwlock_unlock(&tab->lock);<br>@@ -634,11 +588,7 @@<br> /* the insert operation calls this, and is wrlock'd when it does. */<br> /* if you want to call it, you should set the wrlock yourself */<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> static void _ast_hashtab_resize(struct ast_hashtab *tab, const char *file, int lineno, const char *func)<br>-#else<br>-static void ast_hashtab_resize(struct ast_hashtab *tab)<br>-#endif<br> {<br> /* this function is called either internally, when the resize func returns 1, or<br> externally by the user to force a resize of the hash table */<br>@@ -656,14 +606,10 @@<br> tab->array[i] = 0; /* erase old ptrs */<br> }<br> ast_free(tab->array);<br>- if (!(tab->array =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(newsize, sizeof(*(tab->array)), file, lineno, func)<br>-#else<br>- ast_calloc(newsize, sizeof(*(tab->array)))<br>-#endif<br>- ))<br>+ tab->array = __ast_calloc(newsize, sizeof(*(tab->array)), file, lineno, func);<br>+ if (!tab->array) {<br> return;<br>+ }<br> <br> /* now sort the buckets into their rightful new slots */<br> tab->resize_count++;<br>@@ -688,23 +634,15 @@<br> }<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)<br>-#else<br>-struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab)<br>-#endif<br> {<br> /* returns an iterator */<br> struct ast_hashtab_iter *it;<br> <br>- if (!(it =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(1, sizeof(*it), file, lineno, func)<br>-#else<br>- ast_calloc(1, sizeof(*it))<br>-#endif<br>- ))<br>+ it = __ast_calloc(1, sizeof(*it), file, lineno, func);<br>+ if (!it) {<br> return NULL;<br>+ }<br> <br> it->next = tab->tlist;<br> it->tab = tab;<br>@@ -715,23 +653,15 @@<br> }<br> <br> /* use this function to get a write lock */<br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)<br>-#else<br>-struct ast_hashtab_iter *ast_hashtab_start_write_traversal(struct ast_hashtab *tab)<br>-#endif<br> {<br> /* returns an iterator */<br> struct ast_hashtab_iter *it;<br> <br>- if (!(it =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(1, sizeof(*it), file, lineno, func)<br>-#else<br>- ast_calloc(1, sizeof(*it))<br>-#endif<br>- ))<br>+ it = __ast_calloc(1, sizeof(*it), file, lineno, func);<br>+ if (!it) {<br> return NULL;<br>+ }<br> <br> it->next = tab->tlist;<br> it->tab = tab;<br>diff --git a/main/heap.c b/main/heap.c<br>index b7d28ce..0b390f7 100644<br>--- a/main/heap.c<br>+++ b/main/heap.c<br>@@ -109,13 +109,8 @@<br> return 0;<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,<br>- ssize_t index_offset, const char *file, int lineno, const char *func)<br>-#else<br>-struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,<br>- ssize_t index_offset)<br>-#endif<br>+ ssize_t index_offset, const char *file, int lineno, const char *func)<br> {<br> struct ast_heap *h;<br> <br>@@ -128,13 +123,8 @@<br> init_height = 8;<br> }<br> <br>- if (!(h =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_calloc(1, sizeof(*h), file, lineno, func)<br>-#else<br>- ast_calloc(1, sizeof(*h))<br>-#endif<br>- )) {<br>+ h = __ast_calloc(1, sizeof(*h), file, lineno, func);<br>+ if (!h) {<br> return NULL;<br> }<br> <br>@@ -142,13 +132,8 @@<br> h->index_offset = index_offset;<br> h->avail_len = (1 << init_height) - 1;<br> <br>- if (!(h->heap =<br>-#ifdef __AST_DEBUG_MALLOC<br>- __ast_malloc(h->avail_len * sizeof(void *), file, lineno, func)<br>-#else<br>- ast_malloc(h->avail_len * sizeof(void *))<br>-#endif<br>- )) {<br>+ h->heap = __ast_malloc(h->avail_len * sizeof(void *), file, lineno, func);<br>+ if (!h->heap) {<br> ast_free(h);<br> return NULL;<br> }<br>@@ -173,20 +158,12 @@<br> /*!<br> * \brief Add a row of additional storage for the heap.<br> */<br>-static int grow_heap(struct ast_heap *h<br>-#ifdef __AST_DEBUG_MALLOC<br>-, const char *file, int lineno, const char *func<br>-#endif<br>-)<br>+static int grow_heap(struct ast_heap *h, const char *file, int lineno, const char *func)<br> {<br> void **new_heap;<br> size_t new_len = h->avail_len * 2 + 1;<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> new_heap = __ast_realloc(h->heap, new_len * sizeof(void *), file, lineno, func);<br>-#else<br>- new_heap = ast_realloc(h->heap, new_len * sizeof(void *));<br>-#endif<br> if (!new_heap) {<br> return -1;<br> }<br>@@ -242,17 +219,9 @@<br> return i;<br> }<br> <br>-#ifdef __AST_DEBUG_MALLOC<br> int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func)<br>-#else<br>-int ast_heap_push(struct ast_heap *h, void *elm)<br>-#endif<br> {<br>- if (h->cur_len == h->avail_len && grow_heap(h<br>-#ifdef __AST_DEBUG_MALLOC<br>- , file, lineno, func<br>-#endif<br>- )) {<br>+ if (h->cur_len == h->avail_len && grow_heap(h, file, lineno, func)) {<br> return -1;<br> }<br> <br>diff --git a/main/strcompat.c b/main/strcompat.c<br>index c3b4ff1..0034c21 100644<br>--- a/main/strcompat.c<br>+++ b/main/strcompat.c<br>@@ -25,6 +25,7 @@<br> <support_level>core</support_level><br> ***/<br> <br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #include <ctype.h><br>@@ -139,7 +140,7 @@<br> }<br> #endif /* !HAVE_STRNLEN */<br> <br>-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_STRNDUP)<br> char *strndup(const char *s, size_t n)<br> {<br> size_t len = strnlen(s, n);<br>@@ -151,9 +152,9 @@<br> new[len] = '\0';<br> return memcpy(new, s, len);<br> }<br>-#endif /* !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_STRNDUP) */<br> <br>-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_VASPRINTF)<br> int vasprintf(char **strp, const char *fmt, va_list ap)<br> {<br> int size;<br>@@ -171,7 +172,7 @@<br> <br> return size;<br> }<br>-#endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_VASPRINTF) */<br> <br> #ifndef HAVE_TIMERSUB<br> void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)<br>@@ -205,7 +206,7 @@<br> * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF<br> * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.<br> */<br>-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_ASPRINTF)<br> int asprintf(char **str, const char *fmt, ...)<br> {<br> va_list ap;<br>@@ -218,7 +219,7 @@<br> <br> return ret;<br> }<br>-#endif /* !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_ASPRINTF) */<br> <br> #ifndef HAVE_STRTOQ<br> #ifndef LONG_MIN<br>diff --git a/main/stringfields.c b/main/stringfields.c<br>index 7e52bbc..30aa8cd 100644<br>--- a/main/stringfields.c<br>+++ b/main/stringfields.c<br>@@ -55,12 +55,6 @@<br> return (1 << count) - ALLOCATOR_OVERHEAD;<br> }<br> <br>-static void *calloc_wrapper(unsigned int num_structs, size_t struct_size,<br>- const char *file, int lineno, const char *func)<br>-{<br>- return __ast_calloc(num_structs, struct_size, file, lineno, func);<br>-}<br>-<br> /*! \brief add a new block to the pool.<br> * We can only allocate from the topmost pool, so the<br> * fields in *mgr reflect the size of that only.<br>@@ -71,7 +65,8 @@<br> struct ast_string_field_pool *pool;<br> size_t alloc_size = optimal_alloc_size(sizeof(*pool) + size);<br> <br>- if (!(pool = calloc_wrapper(1, alloc_size, file, lineno, func))) {<br>+ pool = __ast_calloc(1, alloc_size, file, lineno, func);<br>+ if (!pool) {<br> return -1;<br> }<br> <br>@@ -184,11 +179,11 @@<br> }<br> <br> mgr->last_alloc = NULL;<br>-#if defined(__AST_DEBUG_MALLOC)<br>+ /* v-- MALLOC_DEBUG information */<br> mgr->owner_file = file;<br> mgr->owner_func = func;<br> mgr->owner_line = lineno;<br>-#endif<br>+ /* ^-- MALLOC_DEBUG information */<br> <br> if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {<br> return -1;<br>@@ -227,13 +222,10 @@<br> new_size *= 2;<br> }<br> <br>-#if defined(__AST_DEBUG_MALLOC)<br>- if (add_string_pool(mgr, pool_head, new_size, mgr->owner_file, mgr->owner_line, mgr->owner_func))<br>+ if (add_string_pool(mgr, pool_head, new_size,<br>+ mgr->owner_file, mgr->owner_line, mgr->owner_func)) {<br> return NULL;<br>-#else<br>- if (add_string_pool(mgr, pool_head, new_size, __FILE__, __LINE__, __FUNCTION__))<br>- return NULL;<br>-#endif<br>+ }<br> }<br> <br> /* pool->base is always aligned (gcc aligned attribute). We ensure that<br>@@ -388,8 +380,8 @@<br> }<br> <br> void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_size,<br>- size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file,<br>- int lineno, const char *func)<br>+ size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size,<br>+ const char *file, int lineno, const char *func)<br> {<br> struct ast_string_field_mgr *mgr;<br> struct ast_string_field_pool *pool;<br>@@ -402,7 +394,8 @@<br> <br> ast_assert(num_structs == 1);<br> <br>- if (!(allocation = calloc_wrapper(num_structs, size_to_alloc, file, lineno, func))) {<br>+ allocation = __ast_calloc(num_structs, size_to_alloc, file, lineno, func);<br>+ if (!allocation) {<br> return NULL;<br> }<br> <br>@@ -426,11 +419,11 @@<br> mgr->embedded_pool = pool;<br> *pool_head = pool;<br> pool->size = size_to_alloc - struct_size - sizeof(*pool);<br>-#if defined(__AST_DEBUG_MALLOC)<br>- mgr->owner_file = file;<br>- mgr->owner_func = func;<br>- mgr->owner_line = lineno;<br>-#endif<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>diff --git a/main/strings.c b/main/strings.c<br>index ad96df2..640af61 100644<br>--- a/main/strings.c<br>+++ b/main/strings.c<br>@@ -52,13 +52,9 @@<br> * ast_str_append_va(...)<br> */<br> <br>-#ifdef __AST_DEBUG_MALLOC<br>-int __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,<br>- int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function)<br>-#else<br> int __ast_str_helper(struct ast_str **buf, ssize_t max_len,<br>- int append, const char *fmt, va_list ap)<br>-#endif<br>+ int append, const char *fmt, va_list ap,<br>+ const char *file, int lineno, const char *function)<br> {<br> int res;<br> int added;<br>@@ -110,13 +106,7 @@<br> need = max_len;<br> }<br> <br>- if (<br>-#ifdef __AST_DEBUG_MALLOC<br>- _ast_str_make_space(buf, need, file, lineno, function)<br>-#else<br>- ast_str_make_space(buf, need)<br>-#endif<br>- ) {<br>+ if (_ast_str_make_space(buf, need, file, lineno, function)) {<br> ast_log_safe(LOG_VERBOSE, "failed to extend from %d to %d\n",<br> (int) (*buf)->__AST_STR_LEN, need);<br> <br>diff --git a/main/utils.c b/main/utils.c<br>index 7f74f40..dab8889 100644<br>--- a/main/utils.c<br>+++ b/main/utils.c<br>@@ -2321,28 +2321,6 @@<br> return 0;<br> }<br> <br>-#ifndef __AST_DEBUG_MALLOC<br>-int __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...)<br>-{<br>- int res;<br>- va_list ap;<br>-<br>- va_start(ap, fmt);<br>- res = vasprintf(ret, fmt, ap);<br>- if (res < 0) {<br>- /*<br>- * *ret is undefined so set to NULL to ensure it is<br>- * initialized to something useful.<br>- */<br>- *ret = NULL;<br>- MALLOC_FAILURE_MSG;<br>- }<br>- va_end(ap);<br>-<br>- return res;<br>-}<br>-#endif<br>-<br> int ast_get_tid(void)<br> {<br> int ret = -1;<br>diff --git a/menuselect/strcompat.c b/menuselect/strcompat.c<br>index c25609f..b78061c 100644<br>--- a/menuselect/strcompat.c<br>+++ b/menuselect/strcompat.c<br>@@ -138,7 +138,7 @@<br> }<br> #endif /* !HAVE_STRNLEN */<br> <br>-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_STRNDUP)<br> char *strndup(const char *s, size_t n)<br> {<br> size_t len = strnlen(s, n);<br>@@ -150,9 +150,9 @@<br> new[len] = '\0';<br> return memcpy(new, s, len);<br> }<br>-#endif /* !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_STRNDUP) */<br> <br>-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_VASPRINTF)<br> int vasprintf(char **strp, const char *fmt, va_list ap)<br> {<br> int size;<br>@@ -170,7 +170,7 @@<br> <br> return size;<br> }<br>-#endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_VASPRINTF) */<br> <br> /*<br> * Based on Code from bsd-asprintf from OpenSSH<br>@@ -191,7 +191,7 @@<br> * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF<br> * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.<br> */<br>-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)<br>+#if !defined(HAVE_ASPRINTF)<br> int asprintf(char **str, const char *fmt, ...)<br> {<br> va_list ap;<br>@@ -204,7 +204,7 @@<br> <br> return ret;<br> }<br>-#endif /* !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) */<br>+#endif /* !defined(HAVE_ASPRINTF) */<br> <br> #ifndef HAVE_GETLOADAVG<br> #ifdef linux<br>diff --git a/res/stasis_recording/stored.c b/res/stasis_recording/stored.c<br>index ac216ff..29c4174 100644<br>--- a/res/stasis_recording/stored.c<br>+++ b/res/stasis_recording/stored.c<br>@@ -123,16 +123,7 @@<br> return -1;<br> }<br> <br>-#if defined(__AST_DEBUG_MALLOC)<br> *dir = ast_strdup(real_dir); /* Dupe so we can ast_free() */<br>-#else<br>- /*<br>- * ast_std_free() and ast_free() are the same thing at this time<br>- * so we don't need to dupe.<br>- */<br>- *dir = real_dir;<br>- real_dir = NULL;<br>-#endif /* defined(__AST_DEBUG_MALLOC) */<br> *file = ast_strdup(file_portion);<br> return 0;<br> }<br>diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.c b/third-party/pjproject/patches/asterisk_malloc_debug.c<br>index aaf7985..061bdd4 100644<br>--- a/third-party/pjproject/patches/asterisk_malloc_debug.c<br>+++ b/third-party/pjproject/patches/asterisk_malloc_debug.c<br>@@ -22,7 +22,7 @@<br> #include <string.h><br> #include <stdarg.h><br> <br>-int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br> {<br> va_list ap;<br> int rc = 0;<br>@@ -34,7 +34,7 @@<br> return rc;<br> }<br> <br>-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br> return calloc(nmemb, size);<br> }<br>@@ -44,27 +44,27 @@<br> free(ptr);<br> }<br> <br>-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)<br> {<br> return malloc(size);<br> }<br> <br>-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br> {<br> return realloc(ptr, size);<br> }<br> <br>-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)<br>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br> {<br> return strdup(s);<br> }<br> <br>-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br> {<br> return strndup(s, n);<br> }<br> <br>-int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br> {<br> return vasprintf(strp, format, ap);<br> }<br>diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.h b/third-party/pjproject/patches/asterisk_malloc_debug.h<br>index 44c4737..e5e04f1 100644<br>--- a/third-party/pjproject/patches/asterisk_malloc_debug.h<br>+++ b/third-party/pjproject/patches/asterisk_malloc_debug.h<br>@@ -25,15 +25,15 @@<br> extern "C" {<br> #endif<br> <br>-int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br> __attribute__((format(printf, 5, 6)));<br>-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br> void __ast_free(void *ptr, const char *file, int lineno, const char *func);<br>-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);<br>-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);<br>-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);<br>-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);<br>-int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);<br>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func);<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);<br>+int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br> __attribute__((format(printf, 2, 0)));<br> <br> /* Undefine any macros */<br>@@ -48,28 +48,28 @@<br> <br> /* Provide our own definitions */<br> #define asprintf(a, b, c...) \<br>- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>+ __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br> <br> #define calloc(a,b) \<br>- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define free(a) \<br> __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define malloc(a) \<br>- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define realloc(a,b) \<br>- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define strdup(a) \<br>- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define strndup(a,b) \<br>- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define vasprintf(a,b,c) \<br>- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_repl_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #ifdef __cplusplus<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8366">change 8366</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/8366"/><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: Ic07ad80b2c2df894db984cf27b16a69383ce0e10 </div>
<div style="display:none"> Gerrit-Change-Number: 8366 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>