From 7b8d8c9bb52fba8c3afd3f05170f54240be3eb48 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 27 Jul 2006 01:49:57 +0000 Subject: [PATCH] fix crashes with MALLOC_DEBUG enabled that were a result of my recent thread storage changes (fixes issue #7595) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38286 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channel.c | 10 +++++++++- cli.c | 11 ++++++++++- utils.c | 11 ++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/channel.c b/channel.c index 2c51b69505..5ee36290bd 100644 --- a/channel.c +++ b/channel.c @@ -160,6 +160,14 @@ const struct ast_cause { { AST_CAUSE_INTERWORKING, "INTERWORKING", "Interworking, unspecified" }, }; +#ifdef __AST_DEBUG_MALLOC +static void FREE(void *ptr) +{ + free(ptr); +} +#else +#define FREE free +#endif struct ast_variable *ast_channeltype_list(void) { @@ -487,7 +495,7 @@ int ast_str2cause(const char *name) static void state2str_buf_key_create(void) { - pthread_key_create(&state2str_buf_key, free); + pthread_key_create(&state2str_buf_key, FREE); } /*! \brief Gives the string form of a given channel state */ diff --git a/cli.c b/cli.c index 205ef7f7a8..6afd56d5e7 100644 --- a/cli.c +++ b/cli.c @@ -57,9 +57,18 @@ static pthread_once_t ast_cli_buf_once = PTHREAD_ONCE_INIT; /*! \brief Initial buffer size for resulting strings in ast_cli() */ #define AST_CLI_MAXSTRLEN 256 +#ifdef __AST_DEBUG_MALLOC +static void FREE(void *ptr) +{ + free(ptr); +} +#else +#define FREE free +#endif + static void ast_cli_buf_key_create(void) { - pthread_key_create(&ast_cli_buf_key, free); + pthread_key_create(&ast_cli_buf_key, FREE); } void ast_cli(int fd, char *fmt, ...) diff --git a/utils.c b/utils.c index 0abc39a773..ef251bfa96 100644 --- a/utils.c +++ b/utils.c @@ -65,6 +65,15 @@ static char b2a[256]; static pthread_key_t inet_ntoa_buf_key; static pthread_once_t inet_ntoa_buf_once = PTHREAD_ONCE_INIT; +#ifdef __AST_DEBUG_MALLOC +static void FREE(void *ptr) +{ + free(ptr); +} +#else +#define FREE free +#endif + #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) || defined(__CYGWIN__) #define ERANGE 34 /*!< duh? ERANGE value copied from web... */ @@ -488,7 +497,7 @@ void ast_uri_decode(char *s) static void inet_ntoa_buf_key_create(void) { - pthread_key_create(&inet_ntoa_buf_key, free); + pthread_key_create(&inet_ntoa_buf_key, FREE); } /*! \brief ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa */