aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-11 03:25:04 +0000
committerjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-11 03:25:04 +0000
commitd16c3fd4ca7637d33efa163106630a4110f7a448 (patch)
tree0cd32982e8825620c5d5bf61f85e3830118f357f /include
parent8e1667bc2d6b310744333ee2e30fd331fd66c70d (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. Because using the ast prefix calls are a better choice, ast_free_ptr is the new wrapper for free to pass to functions. Also, a little bit of clean up was done to avoid the debug macros intentionally being redefined. (closes issue #13593) Reported by: pj git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@181133 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/astmm.h34
-rw-r--r--include/asterisk/threadstorage.h2
-rw-r--r--include/asterisk/utils.h20
3 files changed, 39 insertions, 17 deletions
diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h
index 8e63c85c5..b5c4f51e2 100644
--- a/include/asterisk/astmm.h
+++ b/include/asterisk/astmm.h
@@ -20,6 +20,11 @@
* \brief Asterisk memory usage debugging
*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef _ASTERISK_ASTMM_H
#define _ASTERISK_ASTMM_H
@@ -42,6 +47,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);
@@ -60,30 +66,58 @@ 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__)
+
+#ifdef __cplusplus
+}
+#endif
+
#else
#error "NEVER INCLUDE astmm.h DIRECTLY!!"
#endif /* _ASTERISK_ASTMM_H */
diff --git a/include/asterisk/threadstorage.h b/include/asterisk/threadstorage.h
index 7a08723b1..9a1529030 100644
--- a/include/asterisk/threadstorage.h
+++ b/include/asterisk/threadstorage.h
@@ -65,7 +65,7 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len
* \endcode
*/
#define AST_THREADSTORAGE(name, name_init) \
- AST_THREADSTORAGE_CUSTOM(name, name_init, ast_free)
+ AST_THREADSTORAGE_CUSTOM(name, name_init, ast_free_ptr)
#if !defined(DEBUG_THREADLOCALS)
#define AST_THREADSTORAGE_CUSTOM(name, name_init, cleanup) \
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 44da65e70..f4790deca 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -304,17 +304,18 @@ long int ast_random(void);
/*!
* \brief free() wrapper
*
- * ast_free should be used when a function pointer for free() needs to be passed
+ * 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(void *ptr) attribute_unused;
-static void ast_free(void *ptr)
+static void ast_free_ptr(void *ptr) attribute_unused;
+static void ast_free_ptr(void *ptr)
{
free(ptr);
}
#else
#define ast_free free
+#define ast_free_ptr ast_free
#endif
#ifndef __AST_DEBUG_MALLOC
@@ -497,19 +498,6 @@ int __attribute__((format(printf, 5, 0))) _ast_vasprintf(char **ret, const char
}
)
-#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__)