<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8521">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><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.<br><br>Remove menuselect conflicts between MALLOC_DEBUG and DEBUG_CHAOS as they<br>can now be combined.<br><br>This has multiple benefits:<br>* Simplifies asterisk/utils.h by removing inline functions and use of<br>  the logger.<br>* Removal of these inline functions decreases size of Asterisk and<br>  module binaries by 1% or more.<br>* Puts memory management functions together with and without<br>  MALLOC_DEBUG enabled, simplifying management of the code.<br>* Enables DEBUG_CHAOS for ASTMM_REDIRECT and bundled pjproject.<br><br>Change-Id: If9df4377f74bdbb627461b27a473123e05525887<br>---<br>M build_tools/cflags.xml<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.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, 409 insertions(+), 667 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/build_tools/cflags.xml b/build_tools/cflags.xml<br>index f05f428..c4f9458 100644<br>--- a/build_tools/cflags.xml<br>+++ b/build_tools/cflags.xml<br>@@ -78,11 +78,9 @@<br>                        <support_level>extended</support_level><br>           </member><br>               <member name="MALLOC_DEBUG" displayname="Keep Track of Memory Allocations"><br>-                        <conflict>DEBUG_CHAOS</conflict><br>                  <support_level>core</support_level><br>               </member><br>               <member name="DEBUG_CHAOS" displayname="Randomly FAIL memory allocations or other operations"><br>-                     <conflict>MALLOC_DEBUG</conflict><br>                         <support_level>core</support_level><br>               </member><br>               <member name="ADDRESS_SANITIZER" displayname="Address Sanitizer"><br>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..13ebe03 100644<br>--- a/include/asterisk/astmm.h<br>+++ b/include/asterisk/astmm.h<br>@@ -17,12 +17,11 @@<br>  */<br> <br> /*! \file<br>- * \brief Asterisk memory usage debugging<br>- * This file provides headers for MALLOC_DEBUG, a define used for tracking down<br>- * memory leaks.  It should never be \#included directly; always use the<br>- * MALLOC_DEBUG definition in menuselect to activate those functions.<br>+ * \brief Asterisk memory management routines<br>+ *<br>+ * This file should never be \#included directly, it is included<br>+ * by asterisk.h.<br>  */<br>-<br> <br> #ifdef __cplusplus<br> extern "C" {<br>@@ -32,26 +31,45 @@<br> #define _ASTERISK_ASTMM_H<br> /* IWYU pragma: private, include "asterisk.h" */<br> <br>-#if defined(MALLOC_DEBUG)<br>+#if defined(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_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)));<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>+/* The __ast_repl functions should not used from Asterisk sources, they are exposed<br>+ * for use by ASTMM_REDIRECT and bundled pjproject. */<br>+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;<br>+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc;<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>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func) attribute_malloc;<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc;<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>@@ -123,22 +141,22 @@<br> #if ASTMM_LIBC == ASTMM_REDIRECT<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>-#define malloc(a) \<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_repl_realloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>-#define strdup(a) \<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_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>+#define calloc(nmemb, size) \<br>+       __ast_repl_calloc(nmemb, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define malloc(size) \<br>+     __ast_repl_malloc(size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define free(ptr) \<br>+       __ast_free(ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define realloc(ptr, size) \<br>+      __ast_repl_realloc(ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define strdup(s) \<br>+ __ast_repl_strdup(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define strndup(s, n) \<br>+      __ast_repl_strndup(s, n, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define asprintf(strp, format, args...) \<br>+        __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, strp, format, args)<br>+#define vasprintf(strp, format, ap) \<br>+     __ast_repl_vasprintf(strp, format, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> #elif ASTMM_LIBC == ASTMM_BLOCK<br> <br>@@ -171,6 +189,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..08f67ab 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(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>@@ -190,6 +224,8 @@<br>         struct ast_region *reg;<br>       unsigned int *fence;<br>  int hash;<br>+<br>+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br> <br>        if (!(reg = malloc(size + sizeof(*reg) + sizeof(*fence)))) {<br>          astmm_log("Memory Allocation Failure - '%d' bytes at %s %s() line %d\n",<br>@@ -425,7 +461,7 @@<br>       ast_mutex_unlock(&reglock);<br> }<br> <br>-static void __ast_free_region(void *ptr, const char *file, int lineno, const char *func)<br>+void __ast_free(void *ptr, const char *file, int lineno, const char *func)<br> {<br>    struct ast_region *reg;<br> <br>@@ -466,7 +502,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>+static 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>@@ -489,11 +525,6 @@<br>   }<br> <br>  return ptr;<br>-}<br>-<br>-void __ast_free(void *ptr, const char *file, int lineno, const char *func)<br>-{<br>-  __ast_free_region(ptr, file, lineno, func);<br> }<br> <br> /*!<br>@@ -538,7 +569,7 @@<br>         }<br> <br>  if (!size) {<br>-         __ast_free_region(ptr, file, lineno, func);<br>+          __ast_free(ptr, file, lineno, func);<br>          return NULL;<br>  }<br> <br>@@ -553,7 +584,7 @@<br>                             /* Make sure that the added memory is not zero. */<br>                            memset(new_mem + len, MALLOC_FILLER, size - len);<br>                     }<br>-                    __ast_free_region(ptr, file, lineno, func);<br>+                  __ast_free(ptr, file, lineno, func);<br>          } else {<br>                      /* Make sure that the malloced memory is not zero. */<br>                         memset(new_mem, MALLOC_FILLER, size);<br>@@ -568,12 +599,10 @@<br>  size_t len;<br>   void *ptr;<br> <br>-        if (!s)<br>-              return NULL;<br>-<br>       len = strlen(s) + 1;<br>- if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func, 0)))<br>+     if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func, 0))) {<br>            strcpy(ptr, s);<br>+      }<br> <br>  return ptr;<br> }<br>@@ -582,10 +611,6 @@<br> {<br>     size_t len;<br>   char *ptr;<br>-<br>-        if (!s) {<br>-            return NULL;<br>- }<br> <br>  len = strnlen(s, n);<br>  if ((ptr = __ast_alloc_region(len + 1, FUNC_STRNDUP, file, lineno, func, 0))) {<br>@@ -601,18 +626,21 @@<br>        int size;<br>     va_list ap, ap2;<br>      char s;<br>+      void *ptr;<br> <br>-        *strp = NULL;<br>         va_start(ap, fmt);<br>    va_copy(ap2, ap);<br>     size = vsnprintf(&s, 1, fmt, ap2);<br>        va_end(ap2);<br>- if (!(*strp = __ast_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func, 0))) {<br>+ ptr = __ast_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func, 0);<br>+    if (!ptr) {<br>+          /* As with stdlib *strp is undefined if allocation fails. */<br>          va_end(ap);<br>           return -1;<br>    }<br>-    vsnprintf(*strp, size + 1, fmt, ap);<br>+ vsnprintf(ptr, size + 1, fmt, ap);<br>    va_end(ap);<br>+  *strp = ptr;<br> <br>       return size;<br> }<br>@@ -622,16 +650,18 @@<br>       int size;<br>     va_list ap2;<br>  char s;<br>+      void *ptr;<br> <br>-        *strp = NULL;<br>         va_copy(ap2, ap);<br>     size = vsnprintf(&s, 1, fmt, ap2);<br>        va_end(ap2);<br>- if (!(*strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func, 0))) {<br>-                va_end(ap);<br>+  ptr = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func, 0);<br>+   if (!ptr) {<br>+          /* As with stdlib *strp is undefined if allocation fails. */<br>          return -1;<br>    }<br>-    vsnprintf(*strp, size + 1, fmt, ap);<br>+ vsnprintf(ptr, size + 1, fmt, ap);<br>+   *strp = ptr;<br> <br>       return size;<br> }<br>@@ -1522,16 +1552,22 @@<br> <br> void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br>+        DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<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>+static void *__ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br> {<br>+  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<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>+        DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<br>+<br>        return malloc(size);<br> }<br> <br>@@ -1542,38 +1578,164 @@<br> <br> void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br> {<br>+      DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<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>+       DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<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>+     DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);<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>+     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>    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> {<br>+       DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);<br>+<br>  return vasprintf(strp, format, ap);<br> }<br> <br> #endif     /* defined(__AST_DEBUG_MALLOC) */<br> <br>+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+     void *p;<br>+<br>+  p = __ast_repl_calloc(nmemb, size, file, lineno, func);<br>+      if (!p) {<br>+            MALLOC_FAILURE_MSG;<br>+  }<br>+<br>+ return p;<br>+}<br>+<br>+void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+   void *p;<br>+<br>+  p = __ast_repl_calloc_cache(nmemb, size, file, lineno, func);<br>+        if (!p) {<br>+            MALLOC_FAILURE_MSG;<br>+  }<br>+<br>+ return p;<br>+<br>+}<br>+<br>+void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)<br>+{<br>+    void *p;<br>+<br>+  p = __ast_repl_malloc(size, file, lineno, func);<br>+     if (!p) {<br>+            MALLOC_FAILURE_MSG;<br>+  }<br>+<br>+ return p;<br>+}<br>+<br>+void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)<br>+{<br>+   void *newp;<br>+<br>+       newp = __ast_repl_realloc(ptr, size, file, lineno, func);<br>+    if (!newp) {<br>+         MALLOC_FAILURE_MSG;<br>+  }<br>+<br>+ return newp;<br>+}<br>+<br>+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)<br>+{<br>+  char *newstr = NULL;<br>+<br>+      if (s) {<br>+             newstr = __ast_repl_strdup(s, file, lineno, func);<br>+           if (!newstr) {<br>+                       MALLOC_FAILURE_MSG;<br>+          }<br>+    }<br>+<br>+ return newstr;<br>+}<br>+<br>+char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)<br>+{<br>+     char *newstr = NULL;<br>+<br>+      if (s) {<br>+             newstr = __ast_repl_strndup(s, n, file, lineno, func);<br>+               if (!newstr) {<br>+                       MALLOC_FAILURE_MSG;<br>+          }<br>+    }<br>+<br>+ return newstr;<br>+}<br>+<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>+<br>+       va_start(ap, format);<br>+        res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);<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>+<br>+             MALLOC_FAILURE_MSG;<br>+  }<br>+    va_end(ap);<br>+<br>+       return res;<br>+}<br>+<br>+int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)<br>+{<br>+    int res;<br>+<br>+  res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);<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>+<br>+             MALLOC_FAILURE_MSG;<br>+  }<br>+<br>+ return res;<br>+}<br>+<br> void *ast_std_malloc(size_t size)<br> {<br>    return malloc(size);<br>diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.h b/third-party/pjproject/patches/asterisk_malloc_debug.h<br>index e5e04f1..2a502fa 100644<br>--- a/third-party/pjproject/patches/asterisk_malloc_debug.h<br>+++ b/third-party/pjproject/patches/asterisk_malloc_debug.h<br>@@ -25,14 +25,24 @@<br> extern "C" {<br> #endif<br> <br>+#ifndef attribute_malloc<br>+#ifdef HAVE_ATTRIBUTE_malloc<br>+/* HAVE_ATTRIBUTE_malloc is never defined from pjproject.  This is here as a placeholder<br>+ * hopefully we can just use __attribute__((malloc)) unconditionally. */<br>+#define attribute_malloc __attribute__((malloc))<br>+#else<br>+#define attribute_malloc<br>+#endif<br>+#endif<br>+<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_repl_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) attribute_malloc;<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_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc;<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>+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func) attribute_malloc;<br>+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc;<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>@@ -47,29 +57,29 @@<br> #undef vasprintf<br> <br>  /* Provide our own definitions */<br>-#define asprintf(a, b, c...) \<br>-   __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)<br>+#define asprintf(strp, format, args...) \<br>+    __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, strp, format, args)<br> <br>-#define calloc(a,b) \<br>-  __ast_repl_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define calloc(nmemb, size) \<br>+       __ast_repl_calloc(nmemb, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define free(a) \<br>-       __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define free(ptr) \<br>+  __ast_free(ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define malloc(a) \<br>-    __ast_repl_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define malloc(size) \<br>+        __ast_repl_malloc(size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define realloc(a,b) \<br>- __ast_repl_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define realloc(ptr, size) \<br>+       __ast_repl_realloc(ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define strdup(a) \<br>-      __ast_repl_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define strdup(s) \<br>+   __ast_repl_strdup(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define strndup(a,b) \<br>-    __ast_repl_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define strndup(s, n) \<br>+    __ast_repl_strndup(s, n, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br>-#define vasprintf(a,b,c) \<br>-    __ast_repl_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define vasprintf(strp, format, ap) \<br>+  __ast_repl_vasprintf(strp, format, ap, __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..d62d45f 100644<br>--- a/utils/Makefile<br>+++ b/utils/Makefile<br>@@ -86,7 +86,7 @@<br>        rm -f *.o $(ALL_UTILS) check_expr<br>     rm -f .*.d<br>    rm -f *.s *.i<br>-        rm -f md5.c strcompat.c ast_expr2.c ast_expr2.h ast_expr2f.c pbx_ael.c pval.c hashtab.c lock.c<br>+       rm -f astmm.c md5.c strcompat.c ast_expr2.c ast_expr2.h ast_expr2f.c pbx_ael.c pval.c hashtab.c lock.c<br>        rm -f aelparse.c aelbison.c conf2ael<br>  rm -f threadstorage.c<br>         rm -f utils.c strings.c poll.c version.c sha1.c astobj2.c refcounter<br>@@ -100,10 +100,13 @@<br> <br> astman: astman.o md5.o<br> astman: LIBS+=$(NEWT_LIB)<br>-astman.o: _ASTCFLAGS+=-DNO_MALLOC_DEBUG<br> <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>@@ -134,7 +137,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 +165,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 +174,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: merged </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: 8 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>