Fix memory corruption when trying to get "core show locks".

Review https://reviewboard.asterisk.org/r/2580/ tried to fix the mismatch
in memory pools but had a math error determining the buffer size and
didn't address other similar memory pool mismatches.

* Effectively reverted the previous patch to go in the same direction as
trunk for the returned memory pool of ast_bt_get_symbols().

* Fixed memory leak in ast_bt_get_symbols() when BETTER_BACKTRACES is
defined.

* Fixed some formatting in ast_bt_get_symbols().

* Fixed sig_pri.c freeing memory allocated by libpri when MALLOC_DEBUG is
enabled.

* Fixed __dump_backtrace() freeing memory from ast_bt_get_symbols() when
MALLOC_DEBUG is enabled.

* Moved __dump_backtrace() because of compile issues with the utils
directory.

(closes issue ASTERISK-22221)
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/2778/
........

Merged revisions 397525 from http://svn.asterisk.org/svn/asterisk/branches/1.8


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@397528 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2013-08-23 16:07:18 +00:00
parent 0bdd6ce706
commit 0cd0977454
10 changed files with 90 additions and 78 deletions

View File

@@ -54,6 +54,12 @@ extern "C" {
#undef vasprintf
#undef free
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);

View File

@@ -289,22 +289,6 @@ void ast_remove_lock_info(void *lock_addr);
#endif /* HAVE_BKTR */
#endif /* !defined(LOW_MEMORY) */
#ifdef HAVE_BKTR
static inline void __dump_backtrace(struct ast_bt *bt, int canlog)
{
char **strings;
ssize_t i;
strings = backtrace_symbols(bt->addresses, bt->num_frames);
for (i = 0; i < bt->num_frames; i++)
__ast_mutex_logger("%s\n", strings[i]);
free(strings);
}
#endif
/*!
* \brief log info for the current lock with ast_log().
*

View File

@@ -411,7 +411,7 @@ void *ast_bt_destroy(struct ast_bt *bt);
* \param addresses A list of addresses, such as the ->addresses structure element of struct ast_bt.
* \param num_frames Number of addresses in the addresses list
* \retval NULL Unable to allocate memory
* \return List of strings. Free the entire list with a single ast_free call.
* \return List of strings. Free the entire list with a single ast_std_free call.
* \since 1.6.2.16
*/
char **ast_bt_get_symbols(void **addresses, size_t num_frames);

View File

@@ -459,24 +459,20 @@ char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
long int ast_random(void);
#ifndef __AST_DEBUG_MALLOC
#define ast_std_malloc malloc
#define ast_std_calloc calloc
#define ast_std_realloc realloc
#define ast_std_free free
/*!
* \brief free() wrapper
*
* ast_free_ptr should be used when a function pointer for free() needs to be passed
* as the argument to a function. Otherwise, astmm will cause seg faults.
*/
#ifdef __AST_DEBUG_MALLOC
static void ast_free_ptr(void *ptr) attribute_unused;
static void ast_free_ptr(void *ptr)
{
ast_free(ptr);
}
#else
#define ast_free free
#define ast_free_ptr ast_free
#endif
#ifndef __AST_DEBUG_MALLOC
#define MALLOC_FAILURE_MSG \
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);