diff options
author | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-11 04:06:44 +0000 |
---|---|---|
committer | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-11 04:06:44 +0000 |
commit | 7e7a32a4ed051bbad971705dee155864254a85ad (patch) | |
tree | 452601c0955a6155adba6e987f37ff7628ec58ff | |
parent | 8efd9ab67d1537e03dc7ea02be6c82df4308a47c (diff) |
Fix malloc debug macros to work properly with h323.
The main problem here was that cstdlib was undefining free thereby causing the
proper debug macros to not be used. ast_h323.cxx has been changed to call
ast_free instead to avoid the issue.
A few other issues were addressed:
- There were a few instances of functions improperly passing ast_free instead
of ast_free_ptr.
- Some clean up was done to avoid the debug macros intentionally being redefined.
(copied below from Kevin's commit, appreciate the help)
- disable astmm.h from doing anything when STANDALONE is defined, which is used
by the tools in the utils/ directory that use parts of Asterisk header files in
hackish ways; also ensure that utils/extconf.c and utils/conf2ael.c are
compiled with STANDALONE defined.
(closes issue #13593)
Reported by: pj
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@181135 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | channels/chan_sip.c | 2 | ||||
-rw-r--r-- | channels/h323/ast_h323.cxx | 8 | ||||
-rw-r--r-- | include/asterisk/astmm.h | 38 | ||||
-rw-r--r-- | include/asterisk/utils.h | 15 | ||||
-rw-r--r-- | main/features.c | 2 | ||||
-rw-r--r-- | pbx/pbx_config.c | 2 | ||||
-rw-r--r-- | utils/Makefile | 3 | ||||
-rw-r--r-- | utils/extconf.c | 111 |
8 files changed, 51 insertions, 130 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 77bd396ae..c9d272da8 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -4200,7 +4200,7 @@ static void register_peer_exten(struct sip_peer *peer, int onoff) if (onoff) { if (!ast_exists_extension(NULL, context, ext, 1, NULL)) { ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop", - ast_strdup(peer->name), ast_free, "SIP"); + ast_strdup(peer->name), ast_free_ptr, "SIP"); } } else if (pbx_find_extension(NULL, NULL, &q, context, ext, 1, NULL, "", E_MATCH)) { ast_context_remove_extension(context, ext, 1, NULL); diff --git a/channels/h323/ast_h323.cxx b/channels/h323/ast_h323.cxx index 425961435..0c31569f3 100644 --- a/channels/h323/ast_h323.cxx +++ b/channels/h323/ast_h323.cxx @@ -140,7 +140,7 @@ int PAsteriskLog::Buffer::underflow() int PAsteriskLog::Buffer::sync() { - char *str = strdup(string); + char *str = ast_strdup(string); char *s, *s1; char c; @@ -156,7 +156,7 @@ int PAsteriskLog::Buffer::sync() ast_verbose("%s", s); *s1 = c; } - free(str); + ast_free(str); string = PString(); char *base = string.GetPointer(2000); @@ -2141,7 +2141,7 @@ MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connecti /* tell the H.323 stack */ SetExternalAddress(H323TransportAddress(localIpAddr, localPort), H323TransportAddress(localIpAddr, localPort + 1)); /* clean up allocated memory */ - free(info); + ast_free(info); } /* Get the payload code */ @@ -2388,7 +2388,7 @@ int h323_set_alias(struct oh323_alias *alias) endPoint->SetGateway(); } if (prefix) - free(prefix); + ast_free(prefix); } return 0; } diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h index 553587942..26273c938 100644 --- a/include/asterisk/astmm.h +++ b/include/asterisk/astmm.h @@ -20,9 +20,16 @@ * \brief Asterisk memory usage debugging */ + +#ifdef __cplusplus +extern "C" { +#endif + #ifndef _ASTERISK_ASTMM_H #define _ASTERISK_ASTMM_H +#ifndef STANDALONE + #define __AST_DEBUG_MALLOC #include "asterisk.h" @@ -42,6 +49,7 @@ #undef strndup #undef asprintf #undef vasprintf +#undef free 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); @@ -61,30 +69,60 @@ void __ast_mm_init(void); #define calloc(a,b) \ __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_calloc(a,b) \ + __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define ast_calloc_cache(a,b) \ __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define malloc(a) \ __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_malloc(a) \ + __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define free(a) \ __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_free(a) \ + __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define realloc(a,b) \ __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_realloc(a,b) \ + __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define strdup(a) \ __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_strdup(a) \ + __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define strndup(a,b) \ __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) +#define ast_strndup(a,b) \ + __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + #define asprintf(a, b, c...) \ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c) +#define ast_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__) +#define ast_vasprintf(a,b,c) \ + __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) + +#endif /* !STANDALONE */ + #else #error "NEVER INCLUDE astmm.h DIRECTLY!!" #endif /* _ASTERISK_ASTMM_H */ + +#ifdef __cplusplus +} +#endif diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index c2c88cca2..107444cb9 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -398,7 +398,6 @@ char *ast_process_quotes_and_slashes(char *start, char find, char replace_with); long int ast_random(void); -#define ast_free free /*! * \brief free() wrapper @@ -413,6 +412,7 @@ static void ast_free_ptr(void *ptr) ast_free(ptr); } #else +#define ast_free free #define ast_free_ptr ast_free #endif @@ -598,19 +598,6 @@ int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, c } ) -#else - -/* If astmm is in use, let it handle these. Otherwise, it will report that - all allocations are coming from this header file */ - -#define ast_malloc(a) malloc(a) -#define ast_calloc(a,b) calloc(a,b) -#define ast_realloc(a,b) realloc(a,b) -#define ast_strdup(a) strdup(a) -#define ast_strndup(a,b) strndup(a,b) -#define ast_asprintf(a,b,...) asprintf(a,b,__VA_ARGS__) -#define ast_vasprintf(a,b,c) vasprintf(a,b,c) - #endif /* AST_DEBUG_MALLOC */ #if !defined(ast_strdupa) && defined(__GNUC__) diff --git a/main/features.c b/main/features.c index 2f3dc9932..39e1d5d2d 100644 --- a/main/features.c +++ b/main/features.c @@ -3544,7 +3544,7 @@ static struct ast_parkinglot *build_parkinglot(char *name, struct ast_variable * /* Add a parking extension into the context */ if (!oldparkinglot) { if (!ast_strlen_zero(ast_parking_ext())) { - if (ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), ast_free, registrar) == -1) + if (ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), ast_free_ptr, registrar) == -1) error = 1; } } diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c index 6d29a3f32..0c90ec0ff 100644 --- a/pbx/pbx_config.c +++ b/pbx/pbx_config.c @@ -1754,7 +1754,7 @@ static void pbx_load_users(void) c = altcopy; ext = strsep(&c, ","); while (ext) { - ast_add_extension2(con, 0, ext, 1, NULL, NULL, "Goto", strdup(tmp), ast_free, registrar); + ast_add_extension2(con, 0, ext, 1, NULL, NULL, "Goto", strdup(tmp), ast_free_ptr, registrar); ext = strsep(&c, ","); } } diff --git a/utils/Makefile b/utils/Makefile index fb6f0d1e2..c9acb26e7 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -188,6 +188,9 @@ refcounter: refcounter.o md5.o hashtab.o utils.o strings.o sha1.o strcompat.o th refcounter.o: ASTCFLAGS+=-O0 -DSTANDALONE extconf.o: extconf.c +extconf.o: ASTCFLAGS+=-DSTANDALONE + +conf2ael.o: ASTCFLAGS+=-DSTANDALONE conf2ael: conf2ael.o ast_expr2f.o ast_expr2.o hashtab.o aelbison.o aelparse.o pbx_ael.o pval.o extconf.o strcompat.o diff --git a/utils/extconf.c b/utils/extconf.c index 4d2aa149d..e47e41c17 100644 --- a/utils/extconf.c +++ b/utils/extconf.c @@ -891,10 +891,10 @@ int ast_channel_trylock(struct ast_channel *chan); /* from utils.h */ #define ast_free free +#define ast_free_ptr free #define MALLOC_FAILURE_MSG \ ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); -#ifndef __AST_DEBUG_MALLOC /*! * \brief A wrapper for malloc() @@ -928,97 +928,6 @@ int ast_channel_trylock(struct ast_channel *chan); #define ast_vasprintf(ret, fmt, ap) \ _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap)) -#else - -/* If astmm is in use, let it handle these. Otherwise, it will report that - all allocations are coming from this header file */ - -#undef __ast_calloc -#undef calloc -#undef ast_calloc - -#define ast_malloc(a) malloc(a) -#define ast_calloc(a,b) calloc(a,b) -#define ast_realloc(a,b) realloc(a,b) -#define ast_strdup(a) strdup(a) -#define ast_strndup(a,b) strndup(a,b) -#define ast_asprintf(a,b,...) asprintf(a,b,__VA_ARGS__) -#define ast_vasprintf(a,b,c) vasprintf(a,b,c) - -void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func) -{ - void *p; - - if (!(p = malloc(len))) - MALLOC_FAILURE_MSG; - - return p; -} - -void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func) -{ - void *p; - - if (!(p = calloc(num, len))) - MALLOC_FAILURE_MSG; - - return p; -} - -void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func); - -void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func) -{ - void *p; - - if (!(p = calloc(num, len))) - MALLOC_FAILURE_MSG; - - return p; -} - -void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func) -{ - void *newp; - - if (!(newp = realloc(p, len))) - MALLOC_FAILURE_MSG; - - return newp; -} - -char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func) -{ - char *newstr = NULL; - - if (str) { - if (!(newstr = strdup(str))) - MALLOC_FAILURE_MSG; - } - - return newstr; -} - -char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func) -{ - char *newstr = NULL; - - if (str) { - if (!(newstr = strndup(str, len))) - MALLOC_FAILURE_MSG; - } - - return newstr; -} - -void __ast_free(void *ptr, const char *file, int lineno, const char *func) -{ -#undef free - free(ptr); -} - -#endif /* AST_DEBUG_MALLOC */ - static unsigned int __unsigned_int_flags_dummy; @@ -1044,8 +953,6 @@ struct ast_flags { /* stolen from utils.h */ -#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); /*! @@ -1239,20 +1146,6 @@ int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, c } ) -#else - -/* If astmm is in use, let it handle these. Otherwise, it will report that - all allocations are coming from this header file */ - -#define ast_malloc(a) malloc(a) -#define ast_calloc(a,b) calloc(a,b) -#define ast_realloc(a,b) realloc(a,b) -#define ast_strdup(a) strdup(a) -#define ast_strndup(a,b) strndup(a,b) -#define ast_vasprintf(a,b,c) vasprintf(a,b,c) - -#endif /* AST_DEBUG_MALLOC */ - #if !defined(ast_strdupa) && defined(__GNUC__) /*! \brief duplicate a string in memory from the stack @@ -6092,7 +5985,7 @@ static int pbx_load_config(const char *config_file) lastpri = ipri; if (!ast_opt_dont_warn && !strcmp(realext, "_.")) ast_log(LOG_WARNING, "The use of '_.' for an extension is strongly discouraged and can have unexpected behavior. Please use '_X.' instead at line %d\n", v->lineno); - if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, strdup(data), ast_free, global_registrar)) { + if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, strdup(data), ast_free_ptr, global_registrar)) { ast_log(LOG_WARNING, "Unable to register extension at line %d\n", v->lineno); } } |