<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8521">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Stop using AST_INLINE_API for allocator functions.<br><br>This replaces AST_INLINE_API allocators in utils.h with real functions<br>implemented in astmm.c. Associated macro's are also moved from utils.h<br>to astmm.h. This also removes the _repl namespace from all functions as<br>they are no longer necessary.<br><br>Change-Id: If9df4377f74bdbb627461b27a473123e05525887<br>---<br>M include/asterisk.h<br>M include/asterisk/astmm.h<br>M include/asterisk/utils.h<br>M main/astmm.c<br>M third-party/pjproject/patches/asterisk_malloc_debug.c<br>M third-party/pjproject/patches/asterisk_malloc_debug.h<br>M utils/.gitignore<br>M utils/Makefile<br>M utils/ael_main.c<br>M utils/astman.c<br>M utils/check_expr.c<br>M utils/conf2ael.c<br>M utils/extconf.c<br>13 files changed, 331 insertions(+), 653 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/8521/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk.h b/include/asterisk.h<br>index 27d66b7..c1ed6af 100644<br>--- a/include/asterisk.h<br>+++ b/include/asterisk.h<br>@@ -20,10 +20,7 @@<br> <br> #include "asterisk/autoconfig.h"<br> #include "asterisk/compat.h"<br>-<br>-#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)<br> #include "asterisk/astmm.h"<br>-#endif<br> <br> /* Default to allowing the umask or filesystem ACLs to determine actual file<br> * creation permissions<br>diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h<br>index 4e4a65b..dda9fa9 100644<br>--- a/include/asterisk/astmm.h<br>+++ b/include/asterisk/astmm.h<br>@@ -32,30 +32,37 @@<br> #define _ASTERISK_ASTMM_H<br> /* IWYU pragma: private, include "asterisk.h" */<br> <br>-#if defined(MALLOC_DEBUG)<br>+#if defined(MALLOC_DEBUG) && !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)<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>+void *ast_std_malloc(size_t size) attribute_malloc;<br>+void *ast_std_calloc(size_t nmemb, size_t size) attribute_malloc;<br> void *ast_std_realloc(void *ptr, size_t size);<br> void ast_std_free(void *ptr);<br>+<br>+/*!<br>+ * \brief free() wrapper<br>+ *<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> <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_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;<br>+void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;<br>+void *__ast_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc;<br> void __ast_free(void *ptr, 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_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>- __attribute__((format(printf, 5, 6)));<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_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) attribute_malloc;<br>+char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc;<br>+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+ __attribute__((format(printf, 5, 6))) attribute_malloc;<br>+int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+ __attribute__((format(printf, 2, 0))) attribute_malloc;<br> <br> /*!<br> * \brief ASTMM_LIBC can be defined to control the meaning of standard allocators.<br>@@ -124,21 +131,21 @@<br> <br> /* Redefine libc functions to our own versions */<br> #define calloc(a, b) \<br>- __ast_repl_calloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_calloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define malloc(a) \<br>- __ast_repl_malloc(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_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_repl_realloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_realloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define strdup(a) \<br>- __ast_repl_strdup(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_strdup(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define strndup(a, b) \<br>- __ast_repl_strndup(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_strndup(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> #define asprintf(a, b, c...) \<br>- __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>+ __ast_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>+ __ast_vasprintf(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #elif ASTMM_LIBC == ASTMM_BLOCK<br> <br>@@ -171,6 +178,132 @@<br> #define ast_free(a) \<br> __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>+/*!<br>+ * \brief A wrapper for malloc()<br>+ *<br>+ * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * The argument and return value are the same as malloc()<br>+ */<br>+#define ast_malloc(len) \<br>+ __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for calloc()<br>+ *<br>+ * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * The arguments and return value are the same as calloc()<br>+ */<br>+#define ast_calloc(num, len) \<br>+ __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for calloc() for use in cache pools<br>+ *<br>+ * ast_calloc_cache() is a wrapper for calloc() that will generate an Asterisk log<br>+ * message in the case that the allocation fails. When memory debugging is in use,<br>+ * the memory allocated by this function will be marked as 'cache' so it can be<br>+ * distinguished from normal memory allocations.<br>+ *<br>+ * The arguments and return value are the same as calloc()<br>+ */<br>+#define ast_calloc_cache(num, len) \<br>+ __ast_calloc_cache((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for realloc()<br>+ *<br>+ * ast_realloc() is a wrapper for realloc() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * The arguments and return value are the same as realloc()<br>+ */<br>+#define ast_realloc(p, len) \<br>+ __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for strdup()<br>+ *<br>+ * ast_strdup() is a wrapper for strdup() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * ast_strdup(), unlike strdup(), can safely accept a NULL argument. If a NULL<br>+ * argument is provided, ast_strdup will return NULL without generating any<br>+ * kind of error log message.<br>+ *<br>+ * The argument and return value are the same as strdup()<br>+ */<br>+#define ast_strdup(str) \<br>+ __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for strndup()<br>+ *<br>+ * ast_strndup() is a wrapper for strndup() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * ast_strndup(), unlike strndup(), can safely accept a NULL argument for the<br>+ * string to duplicate. If a NULL argument is provided, ast_strdup will return<br>+ * NULL without generating any kind of error log message.<br>+ *<br>+ * The arguments and return value are the same as strndup()<br>+ */<br>+#define ast_strndup(str, len) \<br>+ __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ * \brief A wrapper for asprintf()<br>+ *<br>+ * ast_asprintf() is a wrapper for asprintf() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * The arguments and return value are the same as asprintf()<br>+ */<br>+#define ast_asprintf(ret, fmt, ...) \<br>+ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)<br>+<br>+/*!<br>+ * \brief A wrapper for vasprintf()<br>+ *<br>+ * ast_vasprintf() is a wrapper for vasprintf() that will generate an Asterisk log<br>+ * message in the case that the allocation fails.<br>+ *<br>+ * The arguments and return value are the same as vasprintf()<br>+ */<br>+#define ast_vasprintf(ret, fmt, ap) \<br>+ __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+<br>+/*!<br>+ \brief call __builtin_alloca to ensure we get gcc builtin semantics<br>+ \param size The size of the buffer we want allocated<br>+<br>+ This macro will attempt to allocate memory from the stack. If it fails<br>+ you won't get a NULL returned, but a SEGFAULT if you're lucky.<br>+*/<br>+#define ast_alloca(size) __builtin_alloca(size)<br>+<br>+#if !defined(ast_strdupa) && defined(__GNUC__)<br>+/*!<br>+ * \brief duplicate a string in memory from the stack<br>+ * \param s The string to duplicate<br>+ *<br>+ * This macro will duplicate the given string. It returns a pointer to the stack<br>+ * allocatted memory for the new string.<br>+ */<br>+#define ast_strdupa(s) \<br>+ (__extension__ \<br>+ ({ \<br>+ const char *__old = (s); \<br>+ size_t __len = strlen(__old) + 1; \<br>+ char *__new = __builtin_alloca(__len); \<br>+ memcpy (__new, __old, __len); \<br>+ __new; \<br>+ }))<br>+#endif<br>+<br> #else<br> #error "NEVER INCLUDE astmm.h DIRECTLY!!"<br> #endif /* _ASTERISK_ASTMM_H */<br>diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h<br>index bb9aa2a..4da7fa4 100644<br>--- a/include/asterisk/utils.h<br>+++ b/include/asterisk/utils.h<br>@@ -484,364 +484,6 @@<br> #define ast_random_double() (((double)ast_random()) / RAND_MAX)<br> <br> /*!<br>- * \brief DEBUG_CHAOS returns failure randomly<br>- *<br>- * DEBUG_CHAOS_RETURN(failure); can be used to fake<br>- * failure of functions such as memory allocation,<br>- * for the purposes of testing failure handling.<br>- */<br>-#ifdef DEBUG_CHAOS<br>-#ifndef DEBUG_CHAOS_ALLOC_CHANCE<br>-#define DEBUG_CHAOS_ALLOC_CHANCE 100000<br>-#endif<br>-/* Could #define DEBUG_CHAOS_ENABLE ast_fully_booted */<br>-#ifndef DEBUG_CHAOS_ENABLE<br>-#define DEBUG_CHAOS_ENABLE 1<br>-#endif<br>-#define DEBUG_CHAOS_RETURN(CHANCE, FAILURE) \<br>- do { \<br>- if ((DEBUG_CHAOS_ENABLE) && (ast_random() % CHANCE == 0)) { \<br>- return FAILURE; \<br>- } \<br>- } while (0)<br>-#else<br>-#define DEBUG_CHAOS_RETURN(c,f)<br>-#endif<br>-<br>-<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>- *<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>-/*<br>- * Need to defeat the MALLOC_DEBUG API when building the standalone utilities.<br>- */<br>-<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>-<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>-#endif<br>-<br>-#if defined(AST_IN_CORE)<br>-#define MALLOC_FAILURE_MSG \<br>- ast_log_safe(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)<br>-#else<br>-#define MALLOC_FAILURE_MSG \<br>- ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)<br>-#endif<br>-<br>-AST_INLINE_API(<br>-void * attribute_malloc __ast_malloc(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_malloc(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(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(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>- return p;<br>-}<br>-)<br>-<br>-AST_INLINE_API(<br>-void *__ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),<br>-{<br>- void *newp;<br>-<br>- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>-<br>- newp = __ast_repl_realloc(p, len, file, lineno, func);<br>- if (!newp) {<br>- MALLOC_FAILURE_MSG;<br>- }<br>-<br>- return newp;<br>-}<br>-)<br>-<br>-AST_INLINE_API(<br>-char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func),<br>-{<br>- char *newstr = NULL;<br>-<br>- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>-<br>- if (str) {<br>- newstr = __ast_repl_strdup(str, file, lineno, func);<br>- if (!newstr) {<br>- MALLOC_FAILURE_MSG;<br>- }<br>- }<br>-<br>- return newstr;<br>-}<br>-)<br>-<br>-AST_INLINE_API(<br>-char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),<br>-{<br>- char *newstr = NULL;<br>-<br>- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>-<br>- if (str) {<br>- newstr = __ast_repl_strndup(str, len, file, lineno, func);<br>- if (!newstr) {<br>- MALLOC_FAILURE_MSG;<br>- }<br>- }<br>-<br>- return newstr;<br>-}<br>-)<br>-<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>-int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func),<br>-{<br>- int res;<br>-<br>- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br>-<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>-<br>- return res;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for malloc()<br>- *<br>- * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The argument and return value are the same as malloc()<br>- */<br>-#define ast_malloc(len) \<br>- __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for calloc()<br>- *<br>- * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as calloc()<br>- */<br>-#define ast_calloc(num, len) \<br>- __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for calloc() for use in cache pools<br>- *<br>- * ast_calloc_cache() is a wrapper for calloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails. When memory debugging is in use,<br>- * the memory allocated by this function will be marked as 'cache' so it can be<br>- * distinguished from normal memory allocations.<br>- *<br>- * The arguments and return value are the same as calloc()<br>- */<br>-#define ast_calloc_cache(num, len) \<br>- __ast_calloc_cache((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for realloc()<br>- *<br>- * ast_realloc() is a wrapper for realloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as realloc()<br>- */<br>-#define ast_realloc(p, len) \<br>- __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for strdup()<br>- *<br>- * ast_strdup() is a wrapper for strdup() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * ast_strdup(), unlike strdup(), can safely accept a NULL argument. If a NULL<br>- * argument is provided, ast_strdup will return NULL without generating any<br>- * kind of error log message.<br>- *<br>- * The argument and return value are the same as strdup()<br>- */<br>-#define ast_strdup(str) \<br>- __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for strndup()<br>- *<br>- * ast_strndup() is a wrapper for strndup() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * ast_strndup(), unlike strndup(), can safely accept a NULL argument for the<br>- * string to duplicate. If a NULL argument is provided, ast_strdup will return<br>- * NULL without generating any kind of error log message.<br>- *<br>- * The arguments and return value are the same as strndup()<br>- */<br>-#define ast_strndup(str, len) \<br>- __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- * \brief A wrapper for asprintf()<br>- *<br>- * ast_asprintf() is a wrapper for asprintf() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as asprintf()<br>- */<br>-#define ast_asprintf(ret, fmt, ...) \<br>- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)<br>-<br>-/*!<br>- * \brief A wrapper for vasprintf()<br>- *<br>- * ast_vasprintf() is a wrapper for vasprintf() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as vasprintf()<br>- */<br>-#define ast_vasprintf(ret, fmt, ap) \<br>- __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-/*!<br>- \brief call __builtin_alloca to ensure we get gcc builtin semantics<br>- \param size The size of the buffer we want allocated<br>-<br>- This macro will attempt to allocate memory from the stack. If it fails<br>- you won't get a NULL returned, but a SEGFAULT if you're lucky.<br>-*/<br>-#define ast_alloca(size) __builtin_alloca(size)<br>-<br>-#if !defined(ast_strdupa) && defined(__GNUC__)<br>-/*!<br>- * \brief duplicate a string in memory from the stack<br>- * \param s The string to duplicate<br>- *<br>- * This macro will duplicate the given string. It returns a pointer to the stack<br>- * allocatted memory for the new string.<br>- */<br>-#define ast_strdupa(s) \<br>- (__extension__ \<br>- ({ \<br>- const char *__old = (s); \<br>- size_t __len = strlen(__old) + 1; \<br>- char *__new = __builtin_alloca(__len); \<br>- memcpy (__new, __old, __len); \<br>- __new; \<br>- }))<br>-#endif<br>-<br>-/*!<br> * \brief Disable PMTU discovery on a socket<br> * \param sock The socket to manipulate<br> * \return Nothing<br>diff --git a/main/astmm.c b/main/astmm.c<br>index 1fa35d7..ebcff7b 100644<br>--- a/main/astmm.c<br>+++ b/main/astmm.c<br>@@ -31,6 +31,40 @@<br> #define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br>+#include "asterisk/logger.h"<br>+<br>+/*!<br>+ * \brief DEBUG_CHAOS returns failure randomly<br>+ *<br>+ * DEBUG_CHAOS_RETURN(failure); can be used to fake<br>+ * failure of functions such as memory allocation,<br>+ * for the purposes of testing failure handling.<br>+ */<br>+#ifdef DEBUG_CHAOS<br>+#ifndef DEBUG_CHAOS_ALLOC_CHANCE<br>+#define DEBUG_CHAOS_ALLOC_CHANCE 100000<br>+#endif<br>+/* Could #define DEBUG_CHAOS_ENABLE ast_fully_booted */<br>+#ifndef DEBUG_CHAOS_ENABLE<br>+#define DEBUG_CHAOS_ENABLE 1<br>+#endif<br>+#define DEBUG_CHAOS_RETURN(CHANCE, FAILURE) \<br>+ do { \<br>+ if ((DEBUG_CHAOS_ENABLE) && (ast_random() % CHANCE == 0)) { \<br>+ return FAILURE; \<br>+ } \<br>+ } while (0)<br>+#else<br>+#define DEBUG_CHAOS_RETURN(c,f)<br>+#endif<br>+<br>+#if defined(NO_MALLOC_DEBUG) || defined(STANDALONE) || defined(STANDALONE2)<br>+#define ast_log_safe ast_log<br>+#endif<br>+<br>+#define MALLOC_FAILURE_MSG \<br>+ ast_log_safe(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)<br>+<br> #if defined(__AST_DEBUG_MALLOC)<br> <br> #include "asterisk/paths.h" /* use ast_config_AST_LOG_DIR */<br>@@ -454,7 +488,7 @@<br> }<br> }<br> <br>-void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br> void *ptr;<br> <br>@@ -466,7 +500,7 @@<br> return ptr;<br> }<br> <br>-void *__ast_repl_calloc_cache(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> {<br> void *ptr;<br> <br>@@ -478,7 +512,7 @@<br> return ptr;<br> }<br> <br>-void *__ast_repl_malloc(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> {<br> void *ptr;<br> <br>@@ -514,7 +548,7 @@<br> return reg;<br> }<br> <br>-void *__ast_repl_realloc(void *ptr, 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> {<br> size_t len;<br> struct ast_region *found;<br>@@ -563,7 +597,7 @@<br> return new_mem;<br> }<br> <br>-char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br>+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)<br> {<br> size_t len;<br> void *ptr;<br>@@ -578,7 +612,7 @@<br> return ptr;<br> }<br> <br>-char *__ast_repl_strndup(const char *s, size_t n, 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> {<br> size_t len;<br> char *ptr;<br>@@ -596,7 +630,7 @@<br> return ptr;<br> }<br> <br>-int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)<br>+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)<br> {<br> int size;<br> va_list ap, ap2;<br>@@ -617,7 +651,7 @@<br> return size;<br> }<br> <br>-int __ast_repl_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)<br>+int __ast_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>@@ -1520,19 +1554,46 @@<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>+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br>- return calloc(nmemb, size);<br>+ void *p;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ p = calloc(nmemb, size);<br>+ if (!p) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return p;<br> }<br> <br>-void *__ast_repl_calloc_cache(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> {<br>- return calloc(nmemb, size);<br>+ void *p;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ p = calloc(nmemb, size);<br>+ if (!p) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return p;<br> }<br> <br>-void *__ast_repl_malloc(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> {<br>- return malloc(size);<br>+ void *p;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ p = malloc(size);<br>+ if (!p) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return p;<br> }<br> <br> void __ast_free(void *ptr, const char *file, int lineno, const char *func)<br>@@ -1540,36 +1601,91 @@<br> free(ptr);<br> }<br> <br>-void *__ast_repl_realloc(void *ptr, 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> {<br>- return realloc(ptr, size);<br>+ void *newp;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ newp = realloc(ptr, size);<br>+ if (!newp) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return newp;<br> }<br> <br>-char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br>+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)<br> {<br>- return strdup(s);<br>+ char *newstr = NULL;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ if (s) {<br>+ newstr = strdup(s);<br>+ if (!newstr) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+ }<br>+<br>+ return newstr;<br> }<br> <br>-char *__ast_repl_strndup(const char *s, size_t n, 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> {<br>- return strndup(s, n);<br>+ char *newstr = NULL;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>+ if (s) {<br>+ newstr = strndup(s, n);<br>+ if (!newstr) {<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+ }<br>+<br>+ return newstr;<br> }<br> <br>-int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br> {<br>+ int res;<br> va_list ap;<br>- int rc = 0;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br> <br> va_start(ap, format);<br>- rc = vasprintf(strp, format, ap);<br>+ res = vasprintf(strp, format, ap);<br>+ if (res < 0) {<br>+ /*<br>+ * *strp is undefined so set to NULL to ensure it is<br>+ * initialized to something useful.<br>+ */<br>+ *strp = NULL;<br>+ MALLOC_FAILURE_MSG;<br>+ }<br> va_end(ap);<br> <br>- return rc;<br>+ return res;<br> }<br> <br>-int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, 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> {<br>- return vasprintf(strp, format, ap);<br>+ int res;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br>+<br>+ res = vasprintf(strp, format, ap);<br>+ if (res < 0) {<br>+ /*<br>+ * *strp is undefined so set to NULL to ensure it is<br>+ * initialized to something useful.<br>+ */<br>+ *strp = NULL;<br>+ MALLOC_FAILURE_MSG;<br>+ }<br>+<br>+ return res;<br> }<br> <br> #endif /* defined(__AST_DEBUG_MALLOC) */<br>diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.c b/third-party/pjproject/patches/asterisk_malloc_debug.c<br>index 061bdd4..aaf7985 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_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+int __ast_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_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+void *__ast_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_repl_malloc(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> {<br> return malloc(size);<br> }<br> <br>-void *__ast_repl_realloc(void *ptr, 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> {<br> return realloc(ptr, size);<br> }<br> <br>-char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)<br>+char *__ast_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>+char *__ast_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_vasprintf(char **strp, const char *format, va_list ap, 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> {<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 e5e04f1..44c4737 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_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br>+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)<br> __attribute__((format(printf, 5, 6)));<br>-void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);<br>+void *__ast_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_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>+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> __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_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>+ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br> <br> #define calloc(a,b) \<br>- __ast_repl_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_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_repl_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define realloc(a,b) \<br>- __ast_repl_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define strdup(a) \<br>- __ast_repl_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define strndup(a,b) \<br>- __ast_repl_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #define vasprintf(a,b,c) \<br>- __ast_repl_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+ __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #ifdef __cplusplus<br> }<br>diff --git a/utils/.gitignore b/utils/.gitignore<br>index dbdc6b6..7840265 100644<br>--- a/utils/.gitignore<br>+++ b/utils/.gitignore<br>@@ -3,6 +3,7 @@<br> aelparse.c<br> ast_expr2.c<br> ast_expr2f.c<br>+astmm.c<br> astman<br> astcanary<br> astdb2bdb<br>diff --git a/utils/Makefile b/utils/Makefile<br>index 3a12754..f98a985 100644<br>--- a/utils/Makefile<br>+++ b/utils/Makefile<br>@@ -105,6 +105,10 @@<br> stereorize: stereorize.o frame.o<br> stereorize: LIBS+=-lm<br> <br>+astmm.c: $(ASTTOPDIR)/main/astmm.c<br>+ $(ECHO_PREFIX) echo " [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"<br>+ $(CMD_PREFIX) cp "$<" "$@"<br>+<br> hashtab.c: $(ASTTOPDIR)/main/hashtab.c<br> $(ECHO_PREFIX) echo " [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"<br> $(CMD_PREFIX) cp "$<" "$@"<br>@@ -134,7 +138,7 @@<br> $(CMD_PREFIX) cp "$<" "$@"<br> ast_expr2f.o: _ASTCFLAGS+=-I$(ASTTOPDIR)/main -Wno-unused<br> <br>-check_expr: check_expr.o ast_expr2.o ast_expr2f.o strcompat.o threadstorage.o clicompat.o<br>+check_expr: check_expr.o ast_expr2.o ast_expr2f.o strcompat.o threadstorage.o clicompat.o astmm.o<br> <br> aelbison.c: $(ASTTOPDIR)/res/ael/ael.tab.c<br> $(ECHO_PREFIX) echo " [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"<br>@@ -162,7 +166,7 @@<br> <br> aelparse.o: _ASTCFLAGS+=-I$(ASTTOPDIR)/res -Wno-unused<br> aelparse: LIBS+=-lm<br>-aelparse: aelparse.o aelbison.o pbx_ael.o hashtab.o lock.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o pval.o extconf.o<br>+aelparse: aelparse.o aelbison.o pbx_ael.o hashtab.o lock.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o pval.o extconf.o astmm.o<br> <br> threadstorage.c: $(ASTTOPDIR)/main/threadstorage.c<br> $(ECHO_PREFIX) echo " [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"<br>@@ -171,15 +175,15 @@<br> <br> extconf.o: extconf.c<br> <br>-conf2ael: conf2ael.o ast_expr2f.o ast_expr2.o hashtab.o lock.o aelbison.o aelparse.o pbx_ael.o pval.o extconf.o strcompat.o<br>+conf2ael: conf2ael.o ast_expr2f.o ast_expr2.o hashtab.o lock.o aelbison.o aelparse.o pbx_ael.o pval.o extconf.o strcompat.o astmm.o<br> <br>-check_expr2: $(ASTTOPDIR)/main/ast_expr2f.c $(ASTTOPDIR)/main/ast_expr2.c $(ASTTOPDIR)/main/ast_expr2.h<br>+check_expr2: $(ASTTOPDIR)/main/ast_expr2f.c $(ASTTOPDIR)/main/ast_expr2.c $(ASTTOPDIR)/main/ast_expr2.h astmm.o<br> $(ECHO_PREFIX) echo " [CC] ast_expr2f.c -> ast_expr2fz.o"<br> $(CC) -g -c -I$(ASTTOPDIR)/include -DSTANDALONE $(ASTTOPDIR)/main/ast_expr2f.c -o ast_expr2fz.o<br> $(ECHO_PREFIX) echo " [CC] ast_expr2.c -> ast_expr2z.o"<br> $(CC) -g -c -I$(ASTTOPDIR)/include -DSTANDALONE2 $(ASTTOPDIR)/main/ast_expr2.c -o ast_expr2z.o<br> $(ECHO_PREFIX) echo " [LD] ast_expr2fz.o ast_expr2z.o -> check_expr2"<br>- $(CC) -g -o check_expr2 ast_expr2fz.o ast_expr2z.o -lm<br>+ $(CC) -g -o check_expr2 ast_expr2fz.o ast_expr2z.o astmm.o -lm<br> $(ECHO_PREFIX) echo " [RM] ast_expr2fz.o ast_expr2z.o"<br> rm ast_expr2z.o ast_expr2fz.o<br> ./check_expr2 expr2.testinput<br>diff --git a/utils/ael_main.c b/utils/ael_main.c<br>index 3a91ef1..f4521e1 100644<br>--- a/utils/ael_main.c<br>+++ b/utils/ael_main.c<br>@@ -11,6 +11,7 @@<br> <support_level>extended</support_level><br> ***/<br> <br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #include <locale.h><br>diff --git a/utils/astman.c b/utils/astman.c<br>index af31851..d4757d0 100644<br>--- a/utils/astman.c<br>+++ b/utils/astman.c<br>@@ -26,6 +26,7 @@<br> <support_level>extended</support_level><br> ***/<br> <br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #include <newt.h><br>diff --git a/utils/check_expr.c b/utils/check_expr.c<br>index 1e4b9d1..d4a4c90 100644<br>--- a/utils/check_expr.c<br>+++ b/utils/check_expr.c<br>@@ -20,6 +20,7 @@<br> <support_level>extended</support_level><br> ***/<br> <br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #include "asterisk/ast_expr.h"<br>diff --git a/utils/conf2ael.c b/utils/conf2ael.c<br>index a8371bb..e3a9056 100644<br>--- a/utils/conf2ael.c<br>+++ b/utils/conf2ael.c<br>@@ -27,6 +27,7 @@<br> <support_level>extended</support_level><br> ***/<br> <br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #include "asterisk/paths.h" /* CONFIG_DIR */<br>diff --git a/utils/extconf.c b/utils/extconf.c<br>index 5b3a95b..b097649 100644<br>--- a/utils/extconf.c<br>+++ b/utils/extconf.c<br>@@ -43,7 +43,7 @@<br> <support_level>extended</support_level><br> ***/<br> <br>-#define ASTMM_LIBC ASTMM_REDIRECT<br>+#define ASTMM_LIBC ASTMM_IGNORE<br> #include "asterisk.h"<br> <br> #undef DEBUG_THREADS<br>@@ -681,9 +681,6 @@<br> <br> /* from utils.h */<br> <br>-#define ast_free free<br>-#define ast_free_ptr free<br>-<br> struct ast_flags { /* stolen from utils.h */<br> unsigned int flags;<br> };<br>@@ -703,222 +700,6 @@<br> else \<br> (p)->flags &= ~(flag); \<br> } while (0)<br>-<br>-<br>-<br>-#define MALLOC_FAILURE_MSG \<br>- ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);<br>-<br>-/*!<br>- * \brief A wrapper for malloc()<br>- *<br>- * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The argument and return value are the same as malloc()<br>- */<br>-#define ast_malloc(len) \<br>- __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func),<br>-{<br>- void *p;<br>-<br>- if (!(p = malloc(len)))<br>- MALLOC_FAILURE_MSG;<br>-<br>- return p;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for calloc()<br>- *<br>- * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as calloc()<br>- */<br>-#define ast_calloc(num, len) \<br>- __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),<br>-{<br>- void *p;<br>-<br>- if (!(p = calloc(num, len)))<br>- MALLOC_FAILURE_MSG;<br>-<br>- return p;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for calloc() for use in cache pools<br>- *<br>- * ast_calloc_cache() is a wrapper for calloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails. When memory debugging is in use,<br>- * the memory allocated by this function will be marked as 'cache' so it can be<br>- * distinguished from normal memory allocations.<br>- *<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>-<br>-/*!<br>- * \brief A wrapper for realloc()<br>- *<br>- * ast_realloc() is a wrapper for realloc() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as realloc()<br>- */<br>-#define ast_realloc(p, len) \<br>- __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-void *__ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),<br>-{<br>- void *newp;<br>-<br>- if (!(newp = realloc(p, len)))<br>- MALLOC_FAILURE_MSG;<br>-<br>- return newp;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for strdup()<br>- *<br>- * ast_strdup() is a wrapper for strdup() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * ast_strdup(), unlike strdup(), can safely accept a NULL argument. If a NULL<br>- * argument is provided, ast_strdup will return NULL without generating any<br>- * kind of error log message.<br>- *<br>- * The argument and return value are the same as strdup()<br>- */<br>-#define ast_strdup(str) \<br>- __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func),<br>-{<br>- char *newstr = NULL;<br>-<br>- if (str) {<br>- if (!(newstr = strdup(str)))<br>- MALLOC_FAILURE_MSG;<br>- }<br>-<br>- return newstr;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for strndup()<br>- *<br>- * ast_strndup() is a wrapper for strndup() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * ast_strndup(), unlike strndup(), can safely accept a NULL argument for the<br>- * string to duplicate. If a NULL argument is provided, ast_strdup will return<br>- * NULL without generating any kind of error log message.<br>- *<br>- * The arguments and return value are the same as strndup()<br>- */<br>-#define ast_strndup(str, len) \<br>- __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),<br>-{<br>- char *newstr = NULL;<br>-<br>- if (str) {<br>- if (!(newstr = strndup(str, len)))<br>- MALLOC_FAILURE_MSG;<br>- }<br>-<br>- return newstr;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for asprintf()<br>- *<br>- * ast_asprintf() is a wrapper for asprintf() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as asprintf()<br>- */<br>-#define ast_asprintf(ret, fmt, ...) \<br>- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)<br>-<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>- va_start(ap, fmt);<br>- if ((res = vasprintf(ret, fmt, ap)) == -1)<br>- MALLOC_FAILURE_MSG;<br>- va_end(ap);<br>-<br>- return res;<br>-}<br>-)<br>-<br>-/*!<br>- * \brief A wrapper for vasprintf()<br>- *<br>- * ast_vasprintf() is a wrapper for vasprintf() that will generate an Asterisk log<br>- * message in the case that the allocation fails.<br>- *<br>- * The arguments and return value are the same as vasprintf()<br>- */<br>-#define ast_vasprintf(ret, fmt, ap) \<br>- __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-<br>-AST_INLINE_API(<br>-__attribute__((format(printf, 2, 0)))<br>-int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func),<br>-{<br>- int res;<br>-<br>- if ((res = vasprintf(ret, fmt, ap)) == -1)<br>- MALLOC_FAILURE_MSG;<br>-<br>- return res;<br>-}<br>-)<br>-<br>-#if !defined(ast_strdupa) && defined(__GNUC__)<br>-/*!<br>- \brief duplicate a string in memory from the stack<br>- \param s The string to duplicate<br>-<br>- This macro will duplicate the given string. It returns a pointer to the stack<br>- allocatted memory for the new string.<br>-*/<br>-#define ast_strdupa(s) \<br>- (__extension__ \<br>- ({ \<br>- const char *__old = (s); \<br>- size_t __len = strlen(__old) + 1; \<br>- char *__new = __builtin_alloca(__len); \<br>- memcpy (__new, __old, __len); \<br>- __new; \<br>- }))<br>-#endif<br>-<br> <br> /* from config.c */<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8521">change 8521</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/8521"/><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: If9df4377f74bdbb627461b27a473123e05525887 </div>
<div style="display:none"> Gerrit-Change-Number: 8521 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>