[Asterisk-code-review] core: Stop using AST INLINE API for allocator functions. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Wed Mar 14 04:43:49 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/8521


Change subject: core: Stop using AST_INLINE_API for allocator functions.
......................................................................

core: Stop using AST_INLINE_API for allocator functions.

This replaces AST_INLINE_API allocators in utils.h with real functions
implemented in astmm.c.  Associated macro's are also moved from utils.h
to astmm.h.  This also removes the _repl namespace from all functions as
they are no longer necessary.

Change-Id: If9df4377f74bdbb627461b27a473123e05525887
---
M include/asterisk.h
M include/asterisk/astmm.h
M include/asterisk/utils.h
M main/astmm.c
M third-party/pjproject/patches/asterisk_malloc_debug.c
M third-party/pjproject/patches/asterisk_malloc_debug.h
M utils/.gitignore
M utils/Makefile
M utils/ael_main.c
M utils/astman.c
M utils/check_expr.c
M utils/conf2ael.c
M utils/extconf.c
13 files changed, 331 insertions(+), 653 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/8521/1

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

-- 
To view, visit https://gerrit.asterisk.org/8521
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If9df4377f74bdbb627461b27a473123e05525887
Gerrit-Change-Number: 8521
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180314/f103c197/attachment-0001.html>


More information about the asterisk-code-review mailing list