Index: astmm.c =================================================================== RCS file: /usr/cvsroot/asterisk/astmm.c,v retrieving revision 1.24 diff -u -r1.24 astmm.c --- astmm.c 16 Nov 2005 02:20:16 -0000 1.24 +++ astmm.c 25 Nov 2005 16:22:33 -0000 @@ -178,7 +178,7 @@ } } -void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) +void *__astmm_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) { void *ptr; ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func); @@ -187,17 +187,17 @@ return ptr; } -void *__ast_malloc(size_t size, const char *file, int lineno, const char *func) +void *__astmm_malloc(size_t size, const char *file, int lineno, const char *func) { return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func); } -void __ast_free(void *ptr, const char *file, int lineno, const char *func) +void __astmm_free(void *ptr, const char *file, int lineno, const char *func) { __ast_free_region(ptr, file, lineno, func); } -void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func) +void *__astmm_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func) { void *tmp; size_t len = 0; @@ -224,7 +224,7 @@ return tmp; } -char *__ast_strdup(const char *s, const char *file, int lineno, const char *func) +char *__astmm_strdup(const char *s, const char *file, int lineno, const char *func) { size_t len; void *ptr; @@ -237,7 +237,7 @@ return ptr; } -char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) +char *__astmm_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) { size_t len; void *ptr; @@ -252,7 +252,7 @@ return ptr; } -int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) +int __astmm_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) { int size; va_list ap2; Index: include/asterisk/astmm.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/astmm.h,v retrieving revision 1.4 diff -u -r1.4 astmm.h --- include/asterisk/astmm.h 24 Oct 2005 20:12:06 -0000 1.4 +++ include/asterisk/astmm.h 25 Nov 2005 16:22:34 -0000 @@ -40,38 +40,38 @@ #undef strndup #undef vasprintf -void *__ast_calloc(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); -void __ast_free(void *ptr, const char *file, int lineno, const char *func); -void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func); -char *__ast_strdup(const char *s, const char *file, int lineno, const char *func); -char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func); -int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func); +void *__astmm_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func); +void *__astmm_malloc(size_t size, const char *file, int lineno, const char *func); +void __astmm_free(void *ptr, const char *file, int lineno, const char *func); +void *__astmm_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func); +char *__astmm_strdup(const char *s, const char *file, int lineno, const char *func); +char *__astmm_strndup(const char *s, size_t n, const char *file, int lineno, const char *func); +int __astmm_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func); void __ast_mm_init(void); /* Provide our own definitions */ #define calloc(a,b) \ - __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define malloc(a) \ - __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define free(a) \ - __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define realloc(a,b) \ - __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define strdup(a) \ - __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define strndup(a,b) \ - __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #define vasprintf(a,b,c) \ - __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) + __astmm_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) #else #error "NEVER INCLUDE astmm.h DIRECTLY!!" Index: include/asterisk/utils.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/utils.h,v retrieving revision 1.51 diff -u -r1.51 utils.h --- include/asterisk/utils.h 8 Nov 2005 04:13:19 -0000 1.51 +++ include/asterisk/utils.h 25 Nov 2005 16:22:35 -0000 @@ -25,6 +25,7 @@ #include "asterisk/compat.h" +#include #include #include /* we want to override inet_ntoa */ #include @@ -33,6 +34,7 @@ #include "asterisk/lock.h" #include "asterisk/time.h" #include "asterisk/strings.h" +#include "asterisk/logger.h" /*! \note \verbatim @@ -235,4 +237,99 @@ int getloadavg(double *list, int nelem); #endif +#define ast_malloc(len) \ + ({ \ + (__ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \ + }) + +AST_INLINE_API( +void *__ast_malloc(size_t len, const char *file, int lineno, const char *func), +{ + void *p; + + p = malloc(len); + + if (!p) + ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file); + + return p; +} +) + +#define ast_calloc(num, len) \ + ({ \ + (__ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \ + }) + +AST_INLINE_API( +void *__ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func), +{ + void *p; + + p = calloc(num, len); + + if (!p) + ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file); + + return p; +} +) + +#define ast_realloc(p, len) \ + ({ \ + (__ast_calloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \ + }) + +AST_INLINE_API( +void *__ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func), +{ + void *newp; + + newp = realloc(p, len); + + if (!newp) + ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file); + + return newp; +} +) + +#define ast_strdup(str) \ + ({ \ + (__ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \ + }) + +AST_INLINE_API( +void *__ast_strdup(char *str, const char *file, int lineno, const char *func), +{ + char *newstr; + + newstr = strdup(str); + + if (!newstr) + ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%s' in function %s at line %d of %s\n", str, func, lineno, file); + + return newstr; +} +) + +#define ast_strndup(str, len) \ + ({ \ + (__ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \ + }) + +AST_INLINE_API( +void *__ast_strndup(char *str, size_t len, const char *file, int lineno, const char *func), +{ + char *newstr; + + newstr = strndup(str, len); + + if (!newstr) + ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%d' bytes of '%s' in function %s at line %d of %s\n", (int)len, str, func, lineno, file); + + return newstr; +} +) + #endif /* _ASTERISK_UTILS_H */