summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2018-03-13 13:54:19 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2018-03-13 13:54:19 -0500
commit4b7872c9db995e99e91fc45adfd133094a51cde3 (patch)
treeb2feecc216608f39b178c0a66503a033217561f3
parenta979e52c0a351b6784530be04c0b096a7428a720 (diff)
parentc711e4076a6913e18e27a694bcb3fb721822fb58 (diff)
Merge "core: Remove ABI effects of MALLOC_DEBUG."
-rw-r--r--CHANGES7
-rw-r--r--UPGRADE.txt6
-rwxr-xr-xbuild_tools/make_buildopts_h17
-rw-r--r--include/asterisk.h2
-rw-r--r--include/asterisk/astmm.h67
-rw-r--r--include/asterisk/chanvars.h8
-rw-r--r--include/asterisk/compat.h6
-rw-r--r--include/asterisk/config.h5
-rw-r--r--include/asterisk/hashtab.h67
-rw-r--r--include/asterisk/heap.h15
-rw-r--r--include/asterisk/stringfields.h4
-rw-r--r--include/asterisk/strings.h69
-rw-r--r--include/asterisk/utils.h111
-rw-r--r--main/astmm.c120
-rw-r--r--main/chanvars.c12
-rw-r--r--main/config.c14
-rw-r--r--main/datastore.c3
-rw-r--r--main/hashtab.c136
-rw-r--r--main/heap.c45
-rw-r--r--main/strcompat.c13
-rw-r--r--main/stringfields.c39
-rw-r--r--main/strings.c16
-rw-r--r--main/utils.c22
-rw-r--r--menuselect/strcompat.c12
-rw-r--r--res/stasis_recording/stored.c11
-rw-r--r--third-party/pjproject/Makefile4
-rw-r--r--third-party/pjproject/patches/asterisk_malloc_debug.c14
-rw-r--r--third-party/pjproject/patches/asterisk_malloc_debug.h28
-rw-r--r--third-party/pjproject/patches/config_site.h2
29 files changed, 390 insertions, 485 deletions
diff --git a/CHANGES b/CHANGES
index 37ec31931..0f4ced2af 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,13 @@ app_fax
* The app_fax module is now deprecated, users should migrate to the
replacement module res_fax.
+Build System
+------------------
+ * MALLOC_DEBUG no longer has an effect on Asterisk's ABI. Asterisk built
+ with MALLOC_DEBUG can now successfully load binary modules built without
+ MALLOC_DEBUG and vice versa. Third-party pre-compiled modules no longer
+ need to have a special build with it enabled.
+
app_macro
------------------
* The app_macro module is now deprecated and by default it is no longer
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 366825863..108c10a01 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -44,6 +44,12 @@ ARI:
- The ContactInfo event's contact_status field is now set to "NonQualified"
when a contact exists but has not been qualified.
+Build System:
+ - MALLOC_DEBUG no longer has an effect on Asterisk's ABI. Asterisk built
+ with MALLOC_DEBUG can now successfully load binary modules built without
+ MALLOC_DEBUG and vice versa. Third-party pre-compiled modules no longer
+ need to have a special build with it enabled.
+
cdr_syslog:
- The cdr_syslog module is now deprecated and by default it is no longer
built.
diff --git a/build_tools/make_buildopts_h b/build_tools/make_buildopts_h
index 3ba4cb9dd..c47d5082c 100755
--- a/build_tools/make_buildopts_h
+++ b/build_tools/make_buildopts_h
@@ -20,18 +20,19 @@ fi
TMP=`${GREP} -e "^MENUSELECT_CFLAGS" menuselect.makeopts | sed 's/MENUSELECT_CFLAGS\=//g' | sed 's/-D//g'`
for x in ${TMP}; do
echo "#define ${x} 1"
- if test "${x}" = "DONT_OPTIMIZE" \
+ if test "${x}" = "AO2_DEBUG" \
-o "${x}" = "BETTER_BACKTRACES" \
- -o "${x}" = "LOTS_OF_SPANS" \
-o "${x}" = "BUILD_NATIVE" \
- -o "${x}" = "LOW_MEMORY" \
- -o "${x}" = "REF_DEBUG" \
- -o "${x}" = "AO2_DEBUG" \
- -o "${x}" = "REBUILD_PARSERS" \
- -o "${x}" = "RADIO_RELAX" \
-o "${x}" = "DEBUG_SCHEDULER" \
-o "${x}" = "DETECT_DEADLOCKS" \
- -o "${x}" = "DUMP_SCHEDULER" ; then
+ -o "${x}" = "DONT_OPTIMIZE" \
+ -o "${x}" = "DUMP_SCHEDULER" \
+ -o "${x}" = "LOTS_OF_SPANS" \
+ -o "${x}" = "LOW_MEMORY" \
+ -o "${x}" = "MALLOC_DEBUG" \
+ -o "${x}" = "RADIO_RELAX" \
+ -o "${x}" = "REBUILD_PARSERS" \
+ -o "${x}" = "REF_DEBUG" ; then
# These aren't ABI affecting options, keep them out of AST_BUILDOPTS
continue
fi
diff --git a/include/asterisk.h b/include/asterisk.h
index 371860278..27d66b776 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -21,7 +21,7 @@
#include "asterisk/autoconfig.h"
#include "asterisk/compat.h"
-#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
+#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)
#include "asterisk/astmm.h"
#endif
diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h
index 06300c861..4e4a65b31 100644
--- a/include/asterisk/astmm.h
+++ b/include/asterisk/astmm.h
@@ -32,27 +32,30 @@ extern "C" {
#define _ASTERISK_ASTMM_H
/* IWYU pragma: private, include "asterisk.h" */
+#if defined(MALLOC_DEBUG)
#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_realloc(void *ptr, size_t size);
void ast_std_free(void *ptr);
void ast_free_ptr(void *ptr);
-void *__ast_calloc(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 *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
+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_free(void *ptr, 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_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+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_vasprintf(char **strp, const char *format, va_list ap, 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)
__attribute__((format(printf, 2, 0)));
-void __ast_mm_init_phase_1(void);
-void __ast_mm_init_phase_2(void);
/*!
* \brief ASTMM_LIBC can be defined to control the meaning of standard allocators.
@@ -120,42 +123,42 @@ void __ast_mm_init_phase_2(void);
#if ASTMM_LIBC == ASTMM_REDIRECT
/* Redefine libc functions to our own versions */
-#define calloc(a,b) \
- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define calloc(a, b) \
+ __ast_repl_calloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define malloc(a) \
- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_malloc(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define free(a) \
- __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-#define realloc(a,b) \
- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define realloc(a, b) \
+ __ast_repl_realloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strdup(a) \
- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-#define strndup(a,b) \
- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_strdup(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define strndup(a, b) \
+ __ast_repl_strndup(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define asprintf(a, b, c...) \
- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
-#define vasprintf(a,b,c) \
- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+#define vasprintf(a, b, c) \
+ __ast_repl_vasprintf(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#elif ASTMM_LIBC == ASTMM_BLOCK
/* Redefine libc functions to cause compile errors */
-#define calloc(a,b) \
- Do_not_use_calloc__use_ast_calloc->fail(a,b)
+#define calloc(a, b) \
+ Do_not_use_calloc__use_ast_calloc->fail(a, b)
#define malloc(a) \
Do_not_use_malloc__use_ast_malloc->fail(a)
#define free(a) \
Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory->fail(a)
-#define realloc(a,b) \
- Do_not_use_realloc__use_ast_realloc->fail(a,b)
+#define realloc(a, b) \
+ Do_not_use_realloc__use_ast_realloc->fail(a, b)
#define strdup(a) \
Do_not_use_strdup__use_ast_strdup->fail(a)
-#define strndup(a,b) \
- Do_not_use_strndup__use_ast_strndup->fail(a,b)
+#define strndup(a, b) \
+ Do_not_use_strndup__use_ast_strndup->fail(a, b)
#define asprintf(a, b, c...) \
- Do_not_use_asprintf__use_ast_asprintf->fail(a,b,c)
-#define vasprintf(a,b,c) \
- Do_not_use_vasprintf__use_ast_vasprintf->fail(a,b,c)
+ Do_not_use_asprintf__use_ast_asprintf->fail(a, b, c)
+#define vasprintf(a, b, c) \
+ Do_not_use_vasprintf__use_ast_vasprintf->fail(a, b, c)
#else
#error "Unacceptable value for the macro ASTMM_LIBC"
@@ -166,7 +169,7 @@ void __ast_mm_init_phase_2(void);
/* Provide our own definition for ast_free */
#define ast_free(a) \
- __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#else
#error "NEVER INCLUDE astmm.h DIRECTLY!!"
diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h
index 2040c7b65..1a303c5f7 100644
--- a/include/asterisk/chanvars.h
+++ b/include/asterisk/chanvars.h
@@ -35,12 +35,10 @@ AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
struct varshead *ast_var_list_create(void);
void ast_var_list_destroy(struct varshead *head);
-#ifdef __AST_DEBUG_MALLOC
+
struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function);
-#define ast_var_assign(a,b) _ast_var_assign(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_var_t *ast_var_assign(const char *name, const char *value);
-#endif
+#define ast_var_assign(name, value) _ast_var_assign(name, value, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
void ast_var_delete(struct ast_var_t *var);
const char *ast_var_name(const struct ast_var_t *var);
const char *ast_var_full_name(const struct ast_var_t *var);
diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h
index 2e89a39eb..85472837c 100644
--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -64,7 +64,7 @@
void closefrom(int lowfd);
#endif
-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_ASPRINTF)
int __attribute__((format(printf, 2, 3))) asprintf(char **str, const char *fmt, ...);
#endif
@@ -96,7 +96,7 @@ int setenv(const char *name, const char *value, int overwrite);
char *strcasestr(const char *, const char *);
#endif
-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_STRNDUP)
char *strndup(const char *, size_t);
#endif
@@ -116,7 +116,7 @@ uint64_t strtoq(const char *nptr, char **endptr, int base);
int unsetenv(const char *name);
#endif
-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_VASPRINTF)
int __attribute__((format(printf, 2, 0))) vasprintf(char **strp, const char *fmt, va_list ap);
#endif
diff --git a/include/asterisk/config.h b/include/asterisk/config.h
index fd9641e99..891284039 100644
--- a/include/asterisk/config.h
+++ b/include/asterisk/config.h
@@ -919,12 +919,9 @@ void ast_category_destroy(struct ast_category *cat);
struct ast_variable *ast_category_detach_variables(struct ast_category *cat);
void ast_category_rename(struct ast_category *cat, const char *name);
-#ifdef __AST_DEBUG_MALLOC
struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno);
#define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#else
-struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename);
-#endif
+
struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size);
struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);
void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file);
diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h
index cfe035b28..64ed1bf6f 100644
--- a/include/asterisk/hashtab.h
+++ b/include/asterisk/hashtab.h
@@ -251,22 +251,15 @@ unsigned int ast_hashtab_hash_short(const short num);
* \param hash a func ptr to do the hashing
* \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now
*/
-#ifdef __AST_DEBUG_MALLOC
-struct ast_hashtab * _ast_hashtab_create(int initial_buckets,
- int (*compare)(const void *a, const void *b),
- int (*resize)(struct ast_hashtab *),
- int (*newsize)(struct ast_hashtab *tab),
- unsigned int (*hash)(const void *obj),
- int do_locking, const char *file, int lineno, const char *function);
-#define ast_hashtab_create(a,b,c,d,e,f) _ast_hashtab_create(a,b,c,d,e,f,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_hashtab * ast_hashtab_create(int initial_buckets,
- int (*compare)(const void *a, const void *b),
- int (*resize)(struct ast_hashtab *),
- int (*newsize)(struct ast_hashtab *tab),
- unsigned int (*hash)(const void *obj),
- int do_locking );
-#endif
+struct ast_hashtab *_ast_hashtab_create(int initial_buckets,
+ int (*compare)(const void *a, const void *b),
+ int (*resize)(struct ast_hashtab *),
+ int (*newsize)(struct ast_hashtab *tab),
+ unsigned int (*hash)(const void *obj),
+ int do_locking,
+ const char *file, int lineno, const char *function);
+#define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking) \
+ _ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief This func will free the hash table and all its memory.
@@ -294,12 +287,9 @@ void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void *
* \retval 1 on success
* \retval 0 if there's a problem
*/
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);
-#define ast_hashtab_insert_immediate(a,b) _ast_hashtab_insert_immediate(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-#else
-int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj);
-#endif
+#define ast_hashtab_insert_immediate(tab, obj) \
+ _ast_hashtab_insert_immediate(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Insert without checking, hashing or locking
@@ -311,12 +301,9 @@ int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj);
* \retval 1 on success
* \retval 0 if there's a problem
*/
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func);
-#define ast_hashtab_insert_immediate_bucket(a,b,c) _ast_hashtab_insert_immediate_bucket(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-#else
-int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h);
-#endif
+#define ast_hashtab_insert_immediate_bucket(tab, obj, h) \
+ _ast_hashtab_insert_immediate_bucket(tab, obj, h, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Check and insert new object only if it is not there.
@@ -324,12 +311,9 @@ int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj
* \retval 1 on success
* \retval 0 if there's a problem, or it's already there.
*/
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);
-#define ast_hashtab_insert_safe(a,b) _ast_hashtab_insert_safe(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-#else
-int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj);
-#endif
+#define ast_hashtab_insert_safe(tab, obj) \
+ _ast_hashtab_insert_safe(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Lookup this object in the hash table.
@@ -362,20 +346,14 @@ int ast_hashtab_size( struct ast_hashtab *tab);
int ast_hashtab_capacity( struct ast_hashtab *tab);
/*! \brief Return a copy of the hash table */
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func);
-#define ast_hashtab_dup(a,b) _ast_hashtab_dup(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj));
-#endif
+#define ast_hashtab_dup(tab, obj_dup_func) \
+ _ast_hashtab_dup(tab, obj_dup_func, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*! \brief Gives an iterator to hastable */
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);
-#define ast_hashtab_start_traversal(a) _ast_hashtab_start_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab);
-#endif
+#define ast_hashtab_start_traversal(tab) \
+ _ast_hashtab_start_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*! \brief end the traversal, free the iterator, unlock if necc. */
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it);
@@ -395,12 +373,9 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj);
/* ------------------ */
/*! \brief Gives an iterator to hastable */
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);
-#define ast_hashtab_start_write_traversal(a) _ast_hashtab_start_write_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_hashtab_iter *ast_hashtab_start_write_traversal(struct ast_hashtab *tab);
-#endif
+#define ast_hashtab_start_write_traversal(tab) \
+ _ast_hashtab_start_write_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*! \brief Looks up the object, removes the corresponding bucket */
void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj);
diff --git a/include/asterisk/heap.h b/include/asterisk/heap.h
index 728327936..83c69a8d6 100644
--- a/include/asterisk/heap.h
+++ b/include/asterisk/heap.h
@@ -97,14 +97,10 @@ typedef int (*ast_heap_cmp_fn)(void *elm1, void *elm2);
* \return An instance of a max heap
* \since 1.6.1
*/
-#ifdef __AST_DEBUG_MALLOC
struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
ssize_t index_offset, const char *file, int lineno, const char *func);
-#define ast_heap_create(a,b,c) _ast_heap_create(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
- ssize_t index_offset);
-#endif
+#define ast_heap_create(init_height, cmp_fn, index_offset) \
+ _ast_heap_create(init_height, cmp_fn, index_offset, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Destroy a max heap
@@ -126,12 +122,9 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h);
* \retval non-zero failure
* \since 1.6.1
*/
-#ifdef __AST_DEBUG_MALLOC
int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func);
-#define ast_heap_push(a,b) _ast_heap_push(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-int ast_heap_push(struct ast_heap *h, void *elm);
-#endif
+#define ast_heap_push(h, elm) \
+ _ast_heap_push(h, elm, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Pop the max element off of the heap
diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h
index 69f2fcca4..5ac5e0973 100644
--- a/include/asterisk/stringfields.h
+++ b/include/asterisk/stringfields.h
@@ -228,11 +228,11 @@ struct ast_string_field_mgr {
ast_string_field last_alloc; /*!< the last field allocated */
struct ast_string_field_pool *embedded_pool; /*!< pointer to the embedded pool, if any */
struct ast_string_field_vector string_fields; /*!< field vector for compare and copy */
-#if defined(__AST_DEBUG_MALLOC)
+ /* v-- MALLOC_DEBUG information */
const char *owner_file; /*!< filename of owner */
const char *owner_func; /*!< function name of owner */
int owner_line; /*!< line number of owner */
-#endif
+ /* ^-- MALLOC_DEBUG information */
};
/*!
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 85393b4f9..e4bef5f0f 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -617,8 +617,8 @@ int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str *
* \note The result of this function is dynamically allocated memory, and must
* be free()'d after it is no longer needed.
*/
-#ifdef __AST_DEBUG_MALLOC
-#define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define ast_str_create(init_len) \
+ _ast_str_create(init_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
struct ast_str * attribute_malloc _ast_str_create(size_t init_len,
const char *file, int lineno, const char *func),
@@ -636,24 +636,6 @@ struct ast_str * attribute_malloc _ast_str_create(size_t init_len,
return buf;
}
)
-#else
-AST_INLINE_API(
-struct ast_str * attribute_malloc ast_str_create(size_t init_len),
-{
- struct ast_str *buf;
-
- buf = (struct ast_str *)ast_calloc(1, sizeof(*buf) + init_len);
- if (buf == NULL)
- return NULL;
-
- buf->__AST_STR_LEN = init_len;
- buf->__AST_STR_USED = 0;
- buf->__AST_STR_TS = DS_MALLOC;
-
- return buf;
-}
-)
-#endif
/*! \brief Reset the content of a dynamic string.
* Useful before a series of ast_str_append.
@@ -772,7 +754,6 @@ char *ast_str_truncate(struct ast_str *buf, ssize_t len),
/*!
* Make space in a new string (e.g. to read in data from a file)
*/
-#ifdef __AST_DEBUG_MALLOC
AST_INLINE_API(
int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function),
{
@@ -796,32 +777,8 @@ int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file,
return 0;
}
)
-#define ast_str_make_space(a,b) _ast_str_make_space(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-AST_INLINE_API(
-int ast_str_make_space(struct ast_str **buf, size_t new_len),
-{
- struct ast_str *old_buf = *buf;
-
- if (new_len <= (*buf)->__AST_STR_LEN)
- return 0; /* success */
- if ((*buf)->__AST_STR_TS == DS_ALLOCA || (*buf)->__AST_STR_TS == DS_STATIC)
- return -1; /* cannot extend */
- *buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));
- if (*buf == NULL) {
- *buf = old_buf;
- return -1;
- }
- if ((*buf)->__AST_STR_TS != DS_MALLOC) {
- pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
- _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
- }
-
- (*buf)->__AST_STR_LEN = new_len;
- return 0;
-}
-)
-#endif
+#define ast_str_make_space(buf, new_len) \
+ _ast_str_make_space(buf, new_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
int ast_str_copy_string(struct ast_str **dst, struct ast_str *src),
@@ -965,14 +922,12 @@ enum {
* through calling one of the other functions or macros defined in this
* file.
*/
-#ifdef __AST_DEBUG_MALLOC
-int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
- int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func);
-#define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)
-#else
-int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, ssize_t max_len,
- int append, const char *fmt, va_list ap);
-#endif
+int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf,
+ ssize_t max_len, int append, const char *fmt, va_list ap,
+ const char *file, int lineno, const char *func);
+#define _ast_str_helper(buf, max_len, append, fmt, ap) \
+ __ast_str_helper(buf, max_len, append, fmt, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,
const char *src, size_t maxsrc, int append, int escapecommas);
@@ -1022,7 +977,7 @@ char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,
*/
AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
{
- return __ast_str_helper(buf, max_len, 0, fmt, ap);
+ return _ast_str_helper(buf, max_len, 0, fmt, ap);
}
)
@@ -1040,7 +995,7 @@ AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct a
*/
AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
{
- return __ast_str_helper(buf, max_len, 1, fmt, ap);
+ return _ast_str_helper(buf, max_len, 1, fmt, ap);
}
)
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c6c34074e..c00310d39 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -509,11 +509,11 @@ long int ast_random(void);
#endif
-#ifndef __AST_DEBUG_MALLOC
-#define ast_std_malloc malloc
-#define ast_std_calloc calloc
-#define ast_std_realloc realloc
-#define ast_std_free free
+#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
@@ -521,8 +521,44 @@ long int ast_random(void);
* 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_free_ptr ast_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 \
@@ -539,7 +575,8 @@ void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, c
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
- if (!(p = malloc(len))) {
+ p = __ast_repl_malloc(len, file, lineno, func);
+ if (!p) {
MALLOC_FAILURE_MSG;
}
@@ -554,7 +591,24 @@ void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, i
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
- if (!(p = calloc(num, len))) {
+ 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;
}
@@ -569,7 +623,8 @@ void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
- if (!(newp = realloc(p, len))) {
+ newp = __ast_repl_realloc(p, len, file, lineno, func);
+ if (!newp) {
MALLOC_FAILURE_MSG;
}
@@ -585,7 +640,8 @@ char * attribute_malloc __ast_strdup(const char *str, const char *file, int line
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
if (str) {
- if (!(newstr = strdup(str))) {
+ newstr = __ast_repl_strdup(str, file, lineno, func);
+ if (!newstr) {
MALLOC_FAILURE_MSG;
}
}
@@ -602,7 +658,8 @@ char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *f
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
if (str) {
- if (!(newstr = strndup(str, len))) {
+ newstr = __ast_repl_strndup(str, len, file, lineno, func);
+ if (!newstr) {
MALLOC_FAILURE_MSG;
}
}
@@ -611,8 +668,30 @@ char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *f
}
)
-int __attribute__((format(printf, 5, 6)))
- __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...);
+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)))
@@ -622,7 +701,7 @@ int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, i
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
- res = vasprintf(ret, fmt, ap);
+ res = __ast_repl_vasprintf(ret, fmt, ap, file, lineno, func);
if (res < 0) {
/*
* *ret is undefined so set to NULL to ensure it is
@@ -636,8 +715,6 @@ int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, i
}
)
-#endif /* AST_DEBUG_MALLOC */
-
/*!
* \brief A wrapper for malloc()
*
@@ -671,7 +748,7 @@ int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, i
* The arguments and return value are the same as calloc()
*/
#define ast_calloc_cache(num, len) \
- __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_calloc_cache((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for realloc()
diff --git a/main/astmm.c b/main/astmm.c
index accd2ffcf..1fa35d728 100644
--- a/main/astmm.c
+++ b/main/astmm.c
@@ -149,31 +149,6 @@ AST_MUTEX_DEFINE_STATIC_NOTRACKING(reglock);
} \
} while (0)
-void *ast_std_malloc(size_t size)
-{
- return malloc(size);
-}
-
-void *ast_std_calloc(size_t nmemb, size_t size)
-{
- return calloc(nmemb, size);
-}
-
-void *ast_std_realloc(void *ptr, size_t size)
-{
- return realloc(ptr, size);
-}
-
-void ast_std_free(void *ptr)
-{
- free(ptr);
-}
-
-void ast_free_ptr(void *ptr)
-{
- ast_free(ptr);
-}
-
static void print_backtrace(struct ast_bt *bt)
{
int i = 0;
@@ -479,7 +454,7 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
}
}
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
void *ptr;
@@ -491,7 +466,7 @@ void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, cons
return ptr;
}
-void *__ast_calloc_cache(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 *ptr;
@@ -503,7 +478,7 @@ void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno
return ptr;
}
-void *__ast_malloc(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 *ptr;
@@ -539,7 +514,7 @@ static struct ast_region *region_find(void *ptr)
return reg;
}
-void *__ast_realloc(void *ptr, 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)
{
size_t len;
struct ast_region *found;
@@ -588,7 +563,7 @@ void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const
return new_mem;
}
-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)
{
size_t len;
void *ptr;
@@ -603,7 +578,7 @@ char *__ast_strdup(const char *s, const char *file, int lineno, const char *func
return ptr;
}
-char *__ast_strndup(const char *s, size_t n, 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)
{
size_t len;
char *ptr;
@@ -621,7 +596,7 @@ char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const
return ptr;
}
-int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)
+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)
{
int size;
va_list ap, ap2;
@@ -642,7 +617,7 @@ int __ast_asprintf(const char *file, int lineno, const char *func, char **strp,
return size;
}
-int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
+int __ast_repl_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
{
int size;
va_list ap2;
@@ -1543,4 +1518,83 @@ void __ast_mm_init_phase_2(void)
ast_register_cleanup(mm_atexit_ast);
}
+#else /* !defined(__AST_DEBUG_MALLOC) */
+
+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+{
+ return calloc(nmemb, size);
+}
+
+void *__ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+{
+ return calloc(nmemb, size);
+}
+
+void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)
+{
+ return malloc(size);
+}
+
+void __ast_free(void *ptr, const char *file, int lineno, const char *func)
+{
+ free(ptr);
+}
+
+void *__ast_repl_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)
+{
+ return strdup(s);
+}
+
+char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
+{
+ return strndup(s, n);
+}
+
+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+{
+ va_list ap;
+ int rc = 0;
+
+ va_start(ap, format);
+ rc = vasprintf(strp, format, ap);
+ va_end(ap);
+
+ return rc;
+}
+
+int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
+{
+ return vasprintf(strp, format, ap);
+}
+
#endif /* defined(__AST_DEBUG_MALLOC) */
+
+void *ast_std_malloc(size_t size)
+{
+ return malloc(size);
+}
+
+void *ast_std_calloc(size_t nmemb, size_t size)
+{
+ return calloc(nmemb, size);
+}
+
+void *ast_std_realloc(void *ptr, size_t size)
+{
+ return realloc(ptr, size);
+}
+
+void ast_std_free(void *ptr)
+{
+ free(ptr);
+}
+
+void ast_free_ptr(void *ptr)
+{
+ ast_free(ptr);
+}
diff --git a/main/chanvars.c b/main/chanvars.c
index 2cc90e43a..0802646b9 100644
--- a/main/chanvars.c
+++ b/main/chanvars.c
@@ -33,21 +33,15 @@
#include "asterisk/strings.h"
#include "asterisk/utils.h"
-#ifdef __AST_DEBUG_MALLOC
struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
-#else
-struct ast_var_t *ast_var_assign(const char *name, const char *value)
-#endif
{
struct ast_var_t *var;
int name_len = strlen(name) + 1;
int value_len = strlen(value) + 1;
-#ifdef __AST_DEBUG_MALLOC
- if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {
-#else
- if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
-#endif
+ var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char),
+ file, lineno, function);
+ if (!var) {
return NULL;
}
diff --git a/main/config.c b/main/config.c
index 38192ed25..dfa6f0923 100644
--- a/main/config.c
+++ b/main/config.c
@@ -281,11 +281,7 @@ struct ast_config_include {
static void ast_variable_destroy(struct ast_variable *doomed);
static void ast_includes_destroy(struct ast_config_include *incls);
-#ifdef __AST_DEBUG_MALLOC
struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *func, int lineno)
-#else
-struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename)
-#endif
{
struct ast_variable *variable;
int name_len = strlen(name) + 1;
@@ -297,13 +293,9 @@ struct ast_variable *ast_variable_new(const char *name, const char *value, const
fn_len = MIN_VARIABLE_FNAME_SPACE;
}
- if (
-#ifdef __AST_DEBUG_MALLOC
- (variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable), file, lineno, func))
-#else
- (variable = ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable)))
-#endif
- ) {
+ variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable),
+ file, lineno, func);
+ if (variable) {
char *dst = variable->stuff; /* writable space starts here */
/* Put file first so ast_include_rename() can calculate space available. */
diff --git a/main/datastore.c b/main/datastore.c
index a12bbdf34..5edad2413 100644
--- a/main/datastore.c
+++ b/main/datastore.c
@@ -47,7 +47,8 @@ struct ast_datastore *__ast_datastore_alloc(
return NULL;
}
- if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) {
+ datastore = __ast_calloc(1, sizeof(*datastore), file, line, function);
+ if (!datastore) {
return NULL;
}
diff --git a/main/hashtab.c b/main/hashtab.c
index eefe44304..1f9c7bfe8 100644
--- a/main/hashtab.c
+++ b/main/hashtab.c
@@ -41,12 +41,10 @@
#include "asterisk/hashtab.h"
-#ifdef __AST_DEBUG_MALLOC
static void _ast_hashtab_resize(struct ast_hashtab *tab, const char *file, int lineno, const char *func);
-#define ast_hashtab_resize(a) _ast_hashtab_resize(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-#else
-static void ast_hashtab_resize(struct ast_hashtab *tab);
-#endif
+#define ast_hashtab_resize(tab) \
+ _ast_hashtab_resize(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
static void *ast_hashtab_lookup_internal(struct ast_hashtab *tab, const void *obj, unsigned int h);
/* some standard, default routines for general use */
@@ -215,40 +213,28 @@ unsigned int ast_hashtab_hash_short(const short x)
return x;
}
-struct ast_hashtab *
-#ifdef __AST_DEBUG_MALLOC
-_ast_hashtab_create
-#else
-ast_hashtab_create
-#endif
-(int initial_buckets,
+struct ast_hashtab *_ast_hashtab_create(int initial_buckets,
int (*compare)(const void *a, const void *b),
int (*resize)(struct ast_hashtab *),
int (*newsize)(struct ast_hashtab *tab),
unsigned int (*hash)(const void *obj),
- int do_locking
-#ifdef __AST_DEBUG_MALLOC
- , const char *file, int lineno, const char *function
-#endif
+ int do_locking,
+ const char *file, int lineno, const char *function
)
{
struct ast_hashtab *ht;
-#ifdef __AST_DEBUG_MALLOC
- if (!(ht = __ast_calloc(1, sizeof(*ht), file, lineno, function)))
-#else
- if (!(ht = ast_calloc(1, sizeof(*ht))))
-#endif
+ ht = __ast_calloc(1, sizeof(*ht), file, lineno, function);
+ if (!ht) {
return NULL;
+ }
while (!ast_is_prime(initial_buckets)) /* make sure this is prime */
initial_buckets++;
-#ifdef __AST_DEBUG_MALLOC
- if (!(ht->array = __ast_calloc(initial_buckets, sizeof(*(ht->array)), file, lineno, function))) {
-#else
- if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) {
-#endif
+ ht->array = __ast_calloc(initial_buckets, sizeof(*(ht->array)),
+ file, lineno, function);
+ if (!ht->array) {
ast_free(ht);
return NULL;
}
@@ -272,25 +258,19 @@ ast_hashtab_create
return ht;
}
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func)
-#else
-struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj))
-#endif
{
struct ast_hashtab *ht;
unsigned int i;
- if (!(ht = ast_calloc(1, sizeof(*ht))))
+ ht = __ast_calloc(1, sizeof(*ht), file, lineno, func);
+ if (!ht) {
return NULL;
+ }
- if (!(ht->array =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)), file, lineno, func)
-#else
- ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)))
-#endif
- )) {
+ ht->array = __ast_calloc(tab->hash_tab_size, sizeof(*(ht->array)),
+ file, lineno, func);
+ if (!ht->array) {
ast_free(ht);
return NULL;
}
@@ -312,12 +292,9 @@ struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_fun
struct ast_hashtab_bucket *b = tab->array[i];
while (b) {
void *newobj = (*obj_dup_func)(b->object);
- if (newobj)
-#ifdef __AST_DEBUG_MALLOC
+ if (newobj) {
_ast_hashtab_insert_immediate_bucket(ht, newobj, i, file, lineno, func);
-#else
- ast_hashtab_insert_immediate_bucket(ht, newobj, i);
-#endif
+ }
b = b->next;
}
}
@@ -424,11 +401,7 @@ void ast_hashtab_destroy(struct ast_hashtab *tab, void (*objdestroyfunc)(void *o
}
}
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)
-#else
-int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
-#endif
{
unsigned int h;
int res=0;
@@ -441,11 +414,7 @@ int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
h = (*tab->hash)(obj) % tab->hash_tab_size;
-#ifdef __AST_DEBUG_MALLOC
res = _ast_hashtab_insert_immediate_bucket(tab, obj, h, file, lineno, func);
-#else
- res = ast_hashtab_insert_immediate_bucket(tab, obj, h);
-#endif
if (tab->do_locking)
ast_rwlock_unlock(&tab->lock);
@@ -453,11 +422,7 @@ int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
return res;
}
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func)
-#else
-int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h)
-#endif
{
int c;
struct ast_hashtab_bucket *b;
@@ -471,13 +436,10 @@ int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj
if (c + 1 > tab->largest_bucket_size)
tab->largest_bucket_size = c + 1;
- if (!(b =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(1, sizeof(*b), file, lineno, func)
-#else
- ast_calloc(1, sizeof(*b))
-#endif
- )) return 0;
+ b = __ast_calloc(1, sizeof(*b), file, lineno, func);
+ if (!b) {
+ return 0;
+ }
b->object = obj;
b->next = tab->array[h];
@@ -495,11 +457,7 @@ int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj
return 1;
}
-#ifdef __AST_DEBUG_MALLOC
int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)
-#else
-int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
-#endif
{
/* check to see if the element is already there; insert only if
it is not there. */
@@ -511,11 +469,7 @@ int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
ast_rwlock_wrlock(&tab->lock);
if (!ast_hashtab_lookup_bucket(tab, obj, &bucket)) {
-#ifdef __AST_DEBUG_MALLOC
int ret2 = _ast_hashtab_insert_immediate_bucket(tab, obj, bucket, file, lineno, func);
-#else
- int ret2 = ast_hashtab_insert_immediate_bucket(tab, obj, bucket);
-#endif
if (tab->do_locking)
ast_rwlock_unlock(&tab->lock);
@@ -634,11 +588,7 @@ int ast_hashtab_capacity( struct ast_hashtab *tab)
/* the insert operation calls this, and is wrlock'd when it does. */
/* if you want to call it, you should set the wrlock yourself */
-#ifdef __AST_DEBUG_MALLOC
static void _ast_hashtab_resize(struct ast_hashtab *tab, const char *file, int lineno, const char *func)
-#else
-static void ast_hashtab_resize(struct ast_hashtab *tab)
-#endif
{
/* this function is called either internally, when the resize func returns 1, or
externally by the user to force a resize of the hash table */
@@ -656,14 +606,10 @@ static void ast_hashtab_resize(struct ast_hashtab *tab)
tab->array[i] = 0; /* erase old ptrs */
}
ast_free(tab->array);
- if (!(tab->array =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(newsize, sizeof(*(tab->array)), file, lineno, func)
-#else
- ast_calloc(newsize, sizeof(*(tab->array)))
-#endif
- ))
+ tab->array = __ast_calloc(newsize, sizeof(*(tab->array)), file, lineno, func);
+ if (!tab->array) {
return;
+ }
/* now sort the buckets into their rightful new slots */
tab->resize_count++;
@@ -688,23 +634,15 @@ static void ast_hashtab_resize(struct ast_hashtab *tab)
}
}
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)
-#else
-struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab)
-#endif
{
/* returns an iterator */
struct ast_hashtab_iter *it;
- if (!(it =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(1, sizeof(*it), file, lineno, func)
-#else
- ast_calloc(1, sizeof(*it))
-#endif
- ))
+ it = __ast_calloc(1, sizeof(*it), file, lineno, func);
+ if (!it) {
return NULL;
+ }
it->next = tab->tlist;
it->tab = tab;
@@ -715,23 +653,15 @@ struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab)
}
/* use this function to get a write lock */
-#ifdef __AST_DEBUG_MALLOC
struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)
-#else
-struct ast_hashtab_iter *ast_hashtab_start_write_traversal(struct ast_hashtab *tab)
-#endif
{
/* returns an iterator */
struct ast_hashtab_iter *it;
- if (!(it =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(1, sizeof(*it), file, lineno, func)
-#else
- ast_calloc(1, sizeof(*it))
-#endif
- ))
+ it = __ast_calloc(1, sizeof(*it), file, lineno, func);
+ if (!it) {
return NULL;
+ }
it->next = tab->tlist;
it->tab = tab;
diff --git a/main/heap.c b/main/heap.c
index b7d28ce2f..0b390f7b8 100644
--- a/main/heap.c
+++ b/main/heap.c
@@ -109,13 +109,8 @@ int ast_heap_verify(struct ast_heap *h)
return 0;
}
-#ifdef __AST_DEBUG_MALLOC
struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
- ssize_t index_offset, const char *file, int lineno, const char *func)
-#else
-struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
- ssize_t index_offset)
-#endif
+ ssize_t index_offset, const char *file, int lineno, const char *func)
{
struct ast_heap *h;
@@ -128,13 +123,8 @@ struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_f
init_height = 8;
}
- if (!(h =
-#ifdef __AST_DEBUG_MALLOC
- __ast_calloc(1, sizeof(*h), file, lineno, func)
-#else
- ast_calloc(1, sizeof(*h))
-#endif
- )) {
+ h = __ast_calloc(1, sizeof(*h), file, lineno, func);
+ if (!h) {
return NULL;
}
@@ -142,13 +132,8 @@ struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_f
h->index_offset = index_offset;
h->avail_len = (1 << init_height) - 1;
- if (!(h->heap =
-#ifdef __AST_DEBUG_MALLOC
- __ast_malloc(h->avail_len * sizeof(void *), file, lineno, func)
-#else
- ast_malloc(h->avail_len * sizeof(void *))
-#endif
- )) {
+ h->heap = __ast_malloc(h->avail_len * sizeof(void *), file, lineno, func);
+ if (!h->heap) {
ast_free(h);
return NULL;
}
@@ -173,20 +158,12 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h)
/*!
* \brief Add a row of additional storage for the heap.
*/
-static int grow_heap(struct ast_heap *h
-#ifdef __AST_DEBUG_MALLOC
-, const char *file, int lineno, const char *func
-#endif
-)
+static int grow_heap(struct ast_heap *h, const char *file, int lineno, const char *func)
{
void **new_heap;
size_t new_len = h->avail_len * 2 + 1;
-#ifdef __AST_DEBUG_MALLOC
new_heap = __ast_realloc(h->heap, new_len * sizeof(void *), file, lineno, func);
-#else
- new_heap = ast_realloc(h->heap, new_len * sizeof(void *));
-#endif
if (!new_heap) {
return -1;
}
@@ -242,17 +219,9 @@ static int bubble_up(struct ast_heap *h, int i)
return i;
}
-#ifdef __AST_DEBUG_MALLOC
int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func)
-#else
-int ast_heap_push(struct ast_heap *h, void *elm)
-#endif
{
- if (h->cur_len == h->avail_len && grow_heap(h
-#ifdef __AST_DEBUG_MALLOC
- , file, lineno, func
-#endif
- )) {
+ if (h->cur_len == h->avail_len && grow_heap(h, file, lineno, func)) {
return -1;
}
diff --git a/main/strcompat.c b/main/strcompat.c
index c3b4ff180..0034c2177 100644
--- a/main/strcompat.c
+++ b/main/strcompat.c
@@ -25,6 +25,7 @@
<support_level>core</support_level>
***/
+#define ASTMM_LIBC ASTMM_IGNORE
#include "asterisk.h"
#include <ctype.h>
@@ -139,7 +140,7 @@ size_t strnlen(const char *s, size_t n)
}
#endif /* !HAVE_STRNLEN */
-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n)
{
size_t len = strnlen(s, n);
@@ -151,9 +152,9 @@ char *strndup(const char *s, size_t n)
new[len] = '\0';
return memcpy(new, s, len);
}
-#endif /* !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_STRNDUP) */
-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_VASPRINTF)
int vasprintf(char **strp, const char *fmt, va_list ap)
{
int size;
@@ -171,7 +172,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
return size;
}
-#endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_VASPRINTF) */
#ifndef HAVE_TIMERSUB
void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
@@ -205,7 +206,7 @@ void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tv
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_ASPRINTF)
int asprintf(char **str, const char *fmt, ...)
{
va_list ap;
@@ -218,7 +219,7 @@ int asprintf(char **str, const char *fmt, ...)
return ret;
}
-#endif /* !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_ASPRINTF) */
#ifndef HAVE_STRTOQ
#ifndef LONG_MIN
diff --git a/main/stringfields.c b/main/stringfields.c
index 7e52bbc9e..30aa8cddd 100644
--- a/main/stringfields.c
+++ b/main/stringfields.c
@@ -55,12 +55,6 @@ static size_t optimal_alloc_size(size_t size)
return (1 << count) - ALLOCATOR_OVERHEAD;
}
-static void *calloc_wrapper(unsigned int num_structs, size_t struct_size,
- const char *file, int lineno, const char *func)
-{
- return __ast_calloc(num_structs, struct_size, file, lineno, func);
-}
-
/*! \brief add a new block to the pool.
* We can only allocate from the topmost pool, so the
* fields in *mgr reflect the size of that only.
@@ -71,7 +65,8 @@ static int add_string_pool(struct ast_string_field_mgr *mgr, struct ast_string_f
struct ast_string_field_pool *pool;
size_t alloc_size = optimal_alloc_size(sizeof(*pool) + size);
- if (!(pool = calloc_wrapper(1, alloc_size, file, lineno, func))) {
+ pool = __ast_calloc(1, alloc_size, file, lineno, func);
+ if (!pool) {
return -1;
}
@@ -184,11 +179,11 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_
}
mgr->last_alloc = NULL;
-#if defined(__AST_DEBUG_MALLOC)
+ /* v-- MALLOC_DEBUG information */
mgr->owner_file = file;
mgr->owner_func = func;
mgr->owner_line = lineno;
-#endif
+ /* ^-- MALLOC_DEBUG information */
if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
return -1;
@@ -227,13 +222,10 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr
new_size *= 2;
}
-#if defined(__AST_DEBUG_MALLOC)
- if (add_string_pool(mgr, pool_head, new_size, mgr->owner_file, mgr->owner_line, mgr->owner_func))
- return NULL;
-#else
- if (add_string_pool(mgr, pool_head, new_size, __FILE__, __LINE__, __FUNCTION__))
+ if (add_string_pool(mgr, pool_head, new_size,
+ mgr->owner_file, mgr->owner_line, mgr->owner_func)) {
return NULL;
-#endif
+ }
}
/* pool->base is always aligned (gcc aligned attribute). We ensure that
@@ -388,8 +380,8 @@ void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
}
void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_size,
- size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file,
- int lineno, const char *func)
+ size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size,
+ const char *file, int lineno, const char *func)
{
struct ast_string_field_mgr *mgr;
struct ast_string_field_pool *pool;
@@ -402,7 +394,8 @@ void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_siz
ast_assert(num_structs == 1);
- if (!(allocation = calloc_wrapper(num_structs, size_to_alloc, file, lineno, func))) {
+ allocation = __ast_calloc(num_structs, size_to_alloc, file, lineno, func);
+ if (!allocation) {
return NULL;
}
@@ -426,11 +419,11 @@ void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_siz
mgr->embedded_pool = pool;
*pool_head = pool;
pool->size = size_to_alloc - struct_size - sizeof(*pool);
-#if defined(__AST_DEBUG_MALLOC)
- mgr->owner_file = file;
- mgr->owner_func = func;
- mgr->owner_line = lineno;
-#endif
+ /* v-- MALLOC_DEBUG information */
+ mgr->owner_file = file;
+ mgr->owner_func = func;
+ mgr->owner_line = lineno;
+ /* ^-- MALLOC_DEBUG information */
return allocation;
}
diff --git a/main/strings.c b/main/strings.c
index ad96df249..640af6123 100644
--- a/main/strings.c
+++ b/main/strings.c
@@ -52,13 +52,9 @@
* ast_str_append_va(...)
*/
-#ifdef __AST_DEBUG_MALLOC
-int __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
- int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function)
-#else
int __ast_str_helper(struct ast_str **buf, ssize_t max_len,
- int append, const char *fmt, va_list ap)
-#endif
+ int append, const char *fmt, va_list ap,
+ const char *file, int lineno, const char *function)
{
int res;
int added;
@@ -110,13 +106,7 @@ int __ast_str_helper(struct ast_str **buf, ssize_t max_len,
need = max_len;
}
- if (
-#ifdef __AST_DEBUG_MALLOC
- _ast_str_make_space(buf, need, file, lineno, function)
-#else
- ast_str_make_space(buf, need)
-#endif
- ) {
+ if (_ast_str_make_space(buf, need, file, lineno, function)) {
ast_log_safe(LOG_VERBOSE, "failed to extend from %d to %d\n",
(int) (*buf)->__AST_STR_LEN, need);
diff --git a/main/utils.c b/main/utils.c
index 928b89bc5..c2e07fccf 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2322,28 +2322,6 @@ int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request,
return 0;
}
-#ifndef __AST_DEBUG_MALLOC
-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);
- res = vasprintf(ret, fmt, ap);
- 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;
-}
-#endif
-
int ast_get_tid(void)
{
int ret = -1;
diff --git a/menuselect/strcompat.c b/menuselect/strcompat.c
index c25609f4b..b78061ca3 100644
--- a/menuselect/strcompat.c
+++ b/menuselect/strcompat.c
@@ -138,7 +138,7 @@ size_t strnlen(const char *s, size_t n)
}
#endif /* !HAVE_STRNLEN */
-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n)
{
size_t len = strnlen(s, n);
@@ -150,9 +150,9 @@ char *strndup(const char *s, size_t n)
new[len] = '\0';
return memcpy(new, s, len);
}
-#endif /* !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_STRNDUP) */
-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_VASPRINTF)
int vasprintf(char **strp, const char *fmt, va_list ap)
{
int size;
@@ -170,7 +170,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
return size;
}
-#endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_VASPRINTF) */
/*
* Based on Code from bsd-asprintf from OpenSSH
@@ -191,7 +191,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
+#if !defined(HAVE_ASPRINTF)
int asprintf(char **str, const char *fmt, ...)
{
va_list ap;
@@ -204,7 +204,7 @@ int asprintf(char **str, const char *fmt, ...)
return ret;
}
-#endif /* !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) */
+#endif /* !defined(HAVE_ASPRINTF) */
#ifndef HAVE_GETLOADAVG
#ifdef linux
diff --git a/res/stasis_recording/stored.c b/res/stasis_recording/stored.c
index ac216ff8c..909524e8f 100644
--- a/res/stasis_recording/stored.c
+++ b/res/stasis_recording/stored.c
@@ -123,18 +123,9 @@ static int split_path(const char *path, char **dir, char **file)
return -1;
}
-#if defined(__AST_DEBUG_MALLOC)
*dir = ast_strdup(real_dir); /* Dupe so we can ast_free() */
-#else
- /*
- * ast_std_free() and ast_free() are the same thing at this time
- * so we don't need to dupe.
- */
- *dir = real_dir;
- real_dir = NULL;
-#endif /* defined(__AST_DEBUG_MALLOC) */
*file = ast_strdup(file_portion);
- return 0;
+ return (*dir && *file) ? 0 : -1;
}
struct match_recording_data {
diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index f7b9f0c3f..b95b33221 100644
--- a/third-party/pjproject/Makefile
+++ b/third-party/pjproject/Makefile
@@ -66,9 +66,9 @@ ifeq ($(SPECIAL_TARGETS),)
endif
ifeq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
CF += -DMALLOC_DEBUG
- MALLOC_DEBUG_LIBS = source/pjsip-apps/lib/libasterisk_malloc_debug.a
- MALLOC_DEBUG_LDFLAGS = -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
endif
+ MALLOC_DEBUG_LIBS = source/pjsip-apps/lib/libasterisk_malloc_debug.a
+ MALLOC_DEBUG_LDFLAGS = -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS)),)
CF += -O3
endif
diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.c b/third-party/pjproject/patches/asterisk_malloc_debug.c
index aaf79855a..061bdd491 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_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
{
va_list ap;
int rc = 0;
@@ -34,7 +34,7 @@ int __ast_asprintf(const char *file, int lineno, const char *func, char **strp,
return rc;
}
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
return calloc(nmemb, size);
}
@@ -44,27 +44,27 @@ void __ast_free(void *ptr, const char *file, int lineno, const char *func)
free(ptr);
}
-void *__ast_malloc(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)
{
return malloc(size);
}
-void *__ast_realloc(void *ptr, 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)
{
return realloc(ptr, size);
}
-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
+char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)
{
return strdup(s);
}
-char *__ast_strndup(const char *s, size_t n, 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)
{
return strndup(s, n);
}
-int __ast_vasprintf(char **strp, const char *format, va_list ap, 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)
{
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 44c473758..e5e04f1af 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_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
__attribute__((format(printf, 5, 6)));
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
+void *__ast_repl_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_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)
+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)
__attribute__((format(printf, 2, 0)));
/* Undefine any macros */
@@ -48,28 +48,28 @@ int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *fil
/* Provide our own definitions */
#define asprintf(a, b, c...) \
- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+ __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
#define calloc(a,b) \
- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define free(a) \
__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define malloc(a) \
- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define realloc(a,b) \
- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strdup(a) \
- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strndup(a,b) \
- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define vasprintf(a,b,c) \
- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_repl_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#ifdef __cplusplus
}
diff --git a/third-party/pjproject/patches/config_site.h b/third-party/pjproject/patches/config_site.h
index d5aee82cc..67e3451d0 100644
--- a/third-party/pjproject/patches/config_site.h
+++ b/third-party/pjproject/patches/config_site.h
@@ -8,7 +8,7 @@
* Since both pjproject and asterisk source files will include config_site.h,
* we need to make sure that only pjproject source files include asterisk_malloc_debug.h.
*/
-#if defined(MALLOC_DEBUG) && !defined(_ASTERISK_ASTMM_H)
+#if !defined(_ASTERISK_ASTMM_H)
#include "asterisk_malloc_debug.h"
#endif