summaryrefslogtreecommitdiff
path: root/main
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 /main
parenta979e52c0a351b6784530be04c0b096a7428a720 (diff)
parentc711e4076a6913e18e27a694bcb3fb721822fb58 (diff)
Merge "core: Remove ABI effects of MALLOC_DEBUG."
Diffstat (limited to 'main')
-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
10 files changed, 161 insertions, 259 deletions
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;