core: Remove ABI effects of MALLOC_DEBUG.

This allows asterisk to be compiled with MALLOC_DEBUG to load modules
built without MALLOC_DEBUG.  Now pre-compiled third-party modules will
still work regardless of MALLOC_DEBUG being enabled or not.

Change-Id: Ic07ad80b2c2df894db984cf27b16a69383ce0e10
This commit is contained in:
Richard Mudgett
2018-02-19 19:55:50 -06:00
parent e58ae393b1
commit c711e4076a
29 changed files with 390 additions and 485 deletions

View File

@@ -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))
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__))
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;
}