[svn-commits] tilghman: branch tilghman/malloc_hold r243116 - in /team/tilghman/malloc_hold...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Jan 26 02:03:33 CST 2010
Author: tilghman
Date: Tue Jan 26 02:03:25 2010
New Revision: 243116
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=243116
Log:
Changes to allow memory debugging to only occur within certain modules.
This is done the same way that we do debugging with astobj2, by setting
a define in the top of the module source. In this case, we #define
MALLOC_HOLD above the first include, and that module gets the MALLOC_HOLD
memory treatment.
Modified:
team/tilghman/malloc_hold/build_tools/cflags.xml
team/tilghman/malloc_hold/channels/chan_sip.c
team/tilghman/malloc_hold/include/asterisk/astmm.h
team/tilghman/malloc_hold/main/astmm.c
team/tilghman/malloc_hold/main/rtp.c
Modified: team/tilghman/malloc_hold/build_tools/cflags.xml
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/malloc_hold/build_tools/cflags.xml?view=diff&rev=243116&r1=243115&r2=243116
==============================================================================
--- team/tilghman/malloc_hold/build_tools/cflags.xml (original)
+++ team/tilghman/malloc_hold/build_tools/cflags.xml Tue Jan 26 02:03:25 2010
@@ -16,9 +16,6 @@
</member>
<member name="MALLOC_DEBUG" displayname="Keep Track of Memory Allocations">
</member>
- <member name="MALLOC_HOLD" displayname="Delay freeing memory, to find possible memory corruptors">
- <depend>MALLOC_DEBUG</depend>
- </member>
<member name="RADIO_RELAX" displayname="Relax DTMF for Radio Applications">
</member>
<member name="STATIC_BUILD" displayname="Build static binaries">
Modified: team/tilghman/malloc_hold/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/malloc_hold/channels/chan_sip.c?view=diff&rev=243116&r1=243115&r2=243116
==============================================================================
--- team/tilghman/malloc_hold/channels/chan_sip.c (original)
+++ team/tilghman/malloc_hold/channels/chan_sip.c Tue Jan 26 02:03:25 2010
@@ -91,6 +91,7 @@
<depend>res_features</depend>
***/
+#define MALLOC_HOLD 1
#include "asterisk.h"
Modified: team/tilghman/malloc_hold/include/asterisk/astmm.h
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/malloc_hold/include/asterisk/astmm.h?view=diff&rev=243116&r1=243115&r2=243116
==============================================================================
--- team/tilghman/malloc_hold/include/asterisk/astmm.h (original)
+++ team/tilghman/malloc_hold/include/asterisk/astmm.h Tue Jan 26 02:03:25 2010
@@ -60,10 +60,78 @@
int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...) __attribute__((format(printf, 5, 6)));
int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func) __attribute__((format(printf, 2, 0)));
+void *__ast_hold_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
+void *__ast_hold_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
+void *__ast_hold_malloc(size_t size, const char *file, int lineno, const char *func);
+void *__ast_hold_malloc_cache(size_t size, const char *file, int lineno, const char *func);
+void *__ast_hold_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
+char *__ast_hold_strdup(const char *s, const char *file, int lineno, const char *func);
+char *__ast_hold_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
+int __ast_hold_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...) __attribute__((format(printf, 5, 6)));
+int __ast_hold_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func) __attribute__((format(printf, 2, 0)));
+
void __ast_mm_init(void);
/* Provide our own definitions */
+#ifdef MALLOC_HOLD
+
+#define calloc(a,b) \
+ __ast_hold_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_calloc(a,b) \
+ __ast_hold_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_calloc_cache(a,b) \
+ __ast_hold_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define malloc(a) \
+ __ast_hold_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_malloc(a) \
+ __ast_hold_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_malloc_cache(a) \
+ __ast_hold_malloc_cache(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_hold_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_realloc(a,b) \
+ __ast_hold_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define strdup(a) \
+ __ast_hold_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_strdup(a) \
+ __ast_hold_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define strndup(a,b) \
+ __ast_hold_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_strndup(a,b) \
+ __ast_hold_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define asprintf(a, b, c...) \
+ __ast_hold_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+
+#define ast_asprintf(a, b, c...) \
+ __ast_hold_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+
+#define vasprintf(a,b,c) \
+ __ast_hold_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define ast_vasprintf(a,b,c) \
+ __ast_hold_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#else /* !defined(MALLOC_HOLD) */
+
#define calloc(a,b) \
__ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
@@ -118,6 +186,8 @@
#define ast_vasprintf(a,b,c) \
__ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#endif /* defined(MALLOC_HOLD) */
+
#ifdef __cplusplus
}
#endif
Modified: team/tilghman/malloc_hold/main/astmm.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/malloc_hold/main/astmm.c?view=diff&rev=243116&r1=243115&r2=243116
==============================================================================
--- team/tilghman/malloc_hold/main/astmm.c (original)
+++ team/tilghman/malloc_hold/main/astmm.c Tue Jan 26 02:03:25 2010
@@ -33,14 +33,12 @@
#include <string.h>
#include <stddef.h>
#include <time.h>
-#ifdef MALLOC_HOLD
#include <sys/mman.h>
#include <signal.h>
#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__Darwin__)
#include <malloc.h>
#endif
#include <errno.h>
-#endif /* MALLOC_HOLD */
#include "asterisk/cli.h"
#include "asterisk/logger.h"
@@ -51,7 +49,6 @@
#define SOME_PRIME 563
-#ifdef MALLOC_HOLD
#define FREE_LIST SOME_PRIME
#define POLLUTED_LIST SOME_PRIME + 1
#define AVAILABLE_LIST SOME_PRIME + 2
@@ -75,7 +72,7 @@
AST_BACKGROUND_STACKSIZE, \
__FILE__, __FUNCTION__, \
__LINE__, #c)
-#endif
+
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
enum func_type {
@@ -102,7 +99,6 @@
static FILE *mmlog = NULL;
-#ifdef MALLOC_HOLD
static ssize_t pagesize = -1;
static struct sigaction default_sigsegv;
@@ -114,7 +110,6 @@
} violations[100] = { { NULL, } };
static int last_violation = -1;
-#endif
/* NOTE: Be EXTREMELY careful with modifying this structure; the total size of this structure
must result in 'automatic' alignment so that the 'fence' field lands exactly at the end of
@@ -132,7 +127,6 @@
struct ast_region *next;
size_t len;
size_t fullsize;
-#ifdef MALLOC_HOLD
char free_file[40];
char free_func[40];
unsigned int free_lineno;
@@ -140,7 +134,6 @@
int mperm;
int operation;
void *vlocation;
-#endif
char alloc_file[40];
char alloc_func[40];
unsigned int alloc_lineno;
@@ -150,13 +143,11 @@
unsigned char data[0];
} *regions[SOME_PRIME + 3];
-#ifdef MALLOC_HOLD
static struct ast_region *lastfree = NULL;
-#endif
#define HASH(a) \
(((unsigned long)(a)) % SOME_PRIME)
-
+
AST_MUTEX_DEFINE_STATIC_NOTRACKING(reglock);
#define astmm_log(...) \
@@ -168,7 +159,6 @@
} \
} while (0)
-#ifdef MALLOC_HOLD
#define MPROTECT(a,b,c) \
do { \
int __p = c; \
@@ -396,15 +386,13 @@
}
ast_mutex_unlock(®lock);
}
-#endif
-
-static inline void *__ast_alloc_region(size_t size, const enum func_type which, const char *file, int lineno, const char *func, unsigned int cache)
+
+static inline void *__ast_hold_alloc_region(size_t size, const enum func_type which, const char *file, int lineno, const char *func, unsigned int cache)
{
struct ast_region *reg = NULL;
void *ptr = NULL;
unsigned int *fence;
int hash;
-#ifdef MALLOC_HOLD
struct ast_region *prev = NULL, *best_prev = NULL, *best_reg = NULL;
size_t fullsize = size + sizeof(*reg) + sizeof(*fence);
@@ -476,21 +464,16 @@
(!cache && !reg && !(reg = memalign(pagesize, fullsize)))
#endif
) {
-#else /* !MALLOC_HOLD */
- if (!(reg = malloc(size + sizeof(*reg) + sizeof(*fence)))) {
-#endif
astmm_log("Memory Allocation Failure - '%d' bytes in function %s "
"at line %d of %s\n", (int) size, func, lineno, file);
return NULL;
}
- ast_copy_string(reg->alloc_file, file, sizeof(reg->alloc_file));
+ ast_copy_string(reg->alloc_file, file + (strlen(file) > sizeof(reg->alloc_file) - 1 ? strlen(file) - sizeof(reg->alloc_file) + 1 : 0), sizeof(reg->alloc_file));
ast_copy_string(reg->alloc_func, func, sizeof(reg->alloc_func));
reg->alloc_lineno = lineno;
reg->len = size;
-#ifdef MALLOC_HOLD
reg->fullsize = fullsize;
-#endif
reg->which = which;
reg->cache = cache;
ptr = reg->data;
@@ -507,6 +490,39 @@
return ptr;
}
+static inline void *__ast_alloc_region(size_t size, const enum func_type which, const char *file, int lineno, const char *func, unsigned int cache)
+{
+ struct ast_region *reg = NULL;
+ void *ptr = NULL;
+ unsigned int *fence;
+ int hash;
+ if (!(reg = malloc(size + sizeof(*reg) + sizeof(*fence)))) {
+ astmm_log("Memory Allocation Failure - '%d' bytes in function %s "
+ "at line %d of %s\n", (int) size, func, lineno, file);
+ return NULL;
+ }
+
+ ast_copy_string(reg->alloc_file, file, sizeof(reg->alloc_file));
+ ast_copy_string(reg->alloc_func, func, sizeof(reg->alloc_func));
+ reg->alloc_lineno = lineno;
+ reg->len = size;
+ reg->fullsize = 1;
+ reg->which = which;
+ reg->cache = cache;
+ ptr = reg->data;
+ hash = HASH(ptr);
+ reg->fence = FENCE_MAGIC;
+ fence = (ptr + reg->len);
+ put_unaligned_uint32(fence, FENCE_MAGIC);
+
+ ast_mutex_lock(®lock);
+ reg->next = regions[hash];
+ regions[hash] = reg;
+ ast_mutex_unlock(®lock);
+
+ return ptr;
+}
+
static inline struct ast_region *ptr2region(void *ptr)
{
int hash = HASH(ptr);
@@ -527,9 +543,7 @@
int hash;
struct ast_region *reg, *prev = NULL;
unsigned int *fence;
-#ifdef MALLOC_HOLD
time_t now;
-#endif
if (!ptr) {
return;
@@ -537,7 +551,6 @@
hash = HASH(ptr);
-#ifdef MALLOC_HOLD
now = time(NULL);
/* Mark this segment as freed */
@@ -549,15 +562,15 @@
astmm_log("WARNING: Low fence violation at %p, in %s of %s, "
"line %d, freed in %s of %s, line %d\n", reg->data,
reg->alloc_func, reg->alloc_file, reg->alloc_lineno,
- reg->free_func, reg->free_file, reg->free_lineno);
+ func, file, lineno);
/* Restore FENCE_MAGIC, as it's needed for extended checking */
reg->fence = FENCE_MAGIC;
}
if (get_unaligned_uint32(fence) != FENCE_MAGIC) {
- astmm_log("WARNING: High fence violation at %p, in %s of %s, "
- "line %d, freed in %s of %s, line %d\n", reg->data,
+ astmm_log("WARNING: High fence violation (%x) at %p, in %s of %s, "
+ "line %d, freed in %s of %s, line %d\n", get_unaligned_uint32(fence), reg->data,
reg->alloc_func, reg->alloc_file, reg->alloc_lineno,
- reg->free_func, reg->free_file, reg->free_lineno);
+ func, file, lineno);
}
/* Remove from "allocated" list */
@@ -601,78 +614,81 @@
}
if (!reg) {
- astmm_log("WARNING: Freeing unused memory at %p, in %s of %s, line %d\n",
+ astmm_log("WARNING: Freeing unused memory at %p, in %s of %s, line %d\n",
ptr, func, file, lineno);
}
ast_mutex_unlock(®lock);
-#else
- ast_mutex_lock(®lock);
- for (reg = regions[hash]; reg; reg = reg->next) {
- if (reg->data == ptr) {
- if (prev)
- prev->next = reg->next;
- else
- regions[hash] = reg->next;
- break;
- }
- prev = reg;
- }
- ast_mutex_unlock(®lock);
-
- if (reg) {
- fence = (unsigned int *)(reg->data + reg->len);
- if (reg->fence != FENCE_MAGIC) {
- astmm_log("WARNING: Low fence violation at %p, in %s of %s, "
- "line %d\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
- }
- if (get_unaligned_uint32(fence) != FENCE_MAGIC) {
- astmm_log("WARNING: High fence violation at %p, in %s of %s, "
- "line %d\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
- }
- free(reg);
- } else {
- astmm_log("WARNING: Freeing unused memory at %p, in %s of %s, line %d\n",
- ptr, func, file, lineno);
- }
-#endif
-}
-
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+}
+
+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
void *ptr;
- if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 0)))
+ if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 0))) {
memset(ptr, 0, size * nmemb);
+ }
return ptr;
}
-void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+void *__ast_hold_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
void *ptr;
- if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 1)))
+ if ((ptr = __ast_hold_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 0))) {
memset(ptr, 0, size * nmemb);
+ }
return ptr;
}
-void *__ast_malloc(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 *ptr;
+
+ if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 1))) {
+ memset(ptr, 0, size * nmemb);
+ }
+ return ptr;
+}
+
+void *__ast_hold_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+{
+ void *ptr;
+
+ if ((ptr = __ast_hold_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 1))) {
+ memset(ptr, 0, size * nmemb);
+ }
+
+ return ptr;
+}
+
+void *__ast_hold_malloc(size_t size, const char *file, int lineno, const char *func)
+{
+ return __ast_hold_alloc_region(size, FUNC_MALLOC, file, lineno, func, 0);
+}
+
+void *__ast_hold_malloc_cache(size_t size, const char *file, int lineno, const char *func)
+{
+ return __ast_hold_alloc_region(size, FUNC_MALLOC, file, lineno, func, 1);
+}
+
+void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)
{
return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func, 0);
}
-void *__ast_malloc_cache(size_t size, const char *file, int lineno, const char *func)
+void *__ast_malloc_cache(size_t size, const char *file, int lineno, const char *func)
{
return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func, 1);
}
-void __ast_free(void *ptr, const char *file, int lineno, const char *func)
+void __ast_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 *__ast_hold_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
{
void *tmp;
struct ast_region *reg = NULL;
@@ -683,22 +699,20 @@
return NULL;
}
-#ifdef MALLOC_HOLD
if (ptr && (size + sizeof(*reg) + sizeof(unsigned int) < reg->fullsize)) {
/* No need to allocate another block, but reset our FENCE_MAGIC now. */
unsigned int *fence = (unsigned int *) (reg->data + reg->len);
if (get_unaligned_uint32(fence) != FENCE_MAGIC) {
astmm_log("WARNING: High fence violation at %p, in %s of %s, "
- "line %d\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
+ "line %d (ast_hold_realloc)\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
}
fence = (unsigned int *) reg->data + size;
reg->len = size;
put_unaligned_uint32(fence, FENCE_MAGIC);
return ptr;
}
-#endif
-
- if (!(tmp = __ast_alloc_region(size, FUNC_REALLOC, file, lineno, func, 0)))
+
+ if (!(tmp = __ast_hold_alloc_region(size, FUNC_REALLOC, file, lineno, func, 0)))
return NULL;
if (ptr) {
@@ -709,36 +723,120 @@
return tmp;
}
-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
+void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
+{
+ void *tmp;
+ struct ast_region *reg = NULL;
+
+ if (ptr && !(reg = ptr2region(ptr))) {
+ astmm_log("WARNING: Realloc of unalloced memory at %p, in %s of %s, "
+ "line %d\n", ptr, func, file, lineno);
+ return NULL;
+ }
+
+ if (!(tmp = __ast_alloc_region(size, FUNC_REALLOC, file, lineno, func, 0)))
+ return NULL;
+
+ if (ptr) {
+ memcpy(tmp, ptr, reg->len);
+ __ast_free_region(ptr, file, lineno, func);
+ }
+
+ return tmp;
+}
+
+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
{
size_t len;
void *ptr;
+ if (!s) {
+ return NULL;
+ }
+
+ len = strlen(s) + 1;
+ if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func, 1))) {
+ strcpy(ptr, s);
+ }
+
+ return ptr;
+}
+
+char *__ast_hold_strdup(const char *s, const char *file, int lineno, const char *func)
+{
+ size_t len;
+ void *ptr;
+
if (!s)
return NULL;
len = strlen(s) + 1;
- if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func, 1)))
+ if ((ptr = __ast_hold_alloc_region(len, FUNC_STRDUP, file, lineno, func, 1))) {
strcpy(ptr, s);
+ }
return ptr;
}
-char *__ast_strndup(const char *s, size_t n, 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)
{
size_t len;
void *ptr;
- if (!s)
+ if (!s) {
return NULL;
+ }
len = strlen(s) + 1;
- if (len > n)
+ if (len > n) {
len = n;
- if ((ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func, 1)))
+ }
+ if ((ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func, 1))) {
strcpy(ptr, s);
+ }
return ptr;
+}
+
+char *__ast_hold_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
+{
+ size_t len;
+ void *ptr;
+
+ if (!s) {
+ return NULL;
+ }
+
+ len = strlen(s) + 1;
+ if (len > n) {
+ len = n;
+ }
+ if ((ptr = __ast_hold_alloc_region(len, FUNC_STRNDUP, file, lineno, func, 1))) {
+ strcpy(ptr, s);
+ }
+
+ return ptr;
+}
+
+int __ast_hold_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)
+{
+ int size;
+ va_list ap, ap2;
+ char s;
+
+ *strp = NULL;
+ va_start(ap, fmt);
+ va_copy(ap2, ap);
+ size = vsnprintf(&s, 1, fmt, ap2);
+ va_end(ap2);
+ if (!(*strp = __ast_hold_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func, 1))) {
+ va_end(ap);
+ return -1;
+ }
+ vsnprintf(*strp, size + 1, fmt, ap);
+ va_end(ap);
+
+ return size;
}
int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...)
@@ -762,7 +860,26 @@
return size;
}
-int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
+int __ast_hold_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
+{
+ int size;
+ va_list ap2;
+ char s;
+
+ *strp = NULL;
+ va_copy(ap2, ap);
+ size = vsnprintf(&s, 1, fmt, ap2);
+ va_end(ap2);
+ if (!(*strp = __ast_hold_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func, 1))) {
+ va_end(ap);
+ return -1;
+ }
+ vsnprintf(*strp, size + 1, fmt, ap);
+
+ return size;
+}
+
+int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
{
int size;
va_list ap2;
@@ -781,7 +898,6 @@
return size;
}
-#ifdef MALLOC_HOLD
static int handle_memory_show_free_available(int fd, int argc, char *argv[])
{
int sizes[100] = { 0, }, i, isfree = 0;
@@ -833,7 +949,6 @@
}
return RESULT_SUCCESS;
}
-#endif
static int handle_show_memory(int fd, int argc, char *argv[])
{
@@ -860,7 +975,7 @@
}
if (get_unaligned_uint32(fence) != FENCE_MAGIC) {
astmm_log("WARNING: High fence violation at %p, in %s of %s, "
- "line %d\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
+ "line %d (handle_show_memory)\n", reg->data, reg->alloc_func, reg->alloc_file, reg->alloc_lineno);
}
}
if (!fn || !strcasecmp(fn, reg->alloc_file)) {
@@ -875,12 +990,12 @@
}
}
ast_mutex_unlock(®lock);
-
+
if (cache_len)
ast_cli(fd, "%d bytes allocated (%d in caches) in %d allocations\n", len, cache_len, count);
else
ast_cli(fd, "%d bytes allocated in %d allocations\n", len, count);
-
+
return RESULT_SUCCESS;
}
@@ -899,9 +1014,10 @@
int count;
struct file_summary *next;
} *list = NULL, *cur;
-
- if (argc > 3)
+
+ if (argc > 3) {
fn = argv[3];
+ }
ast_mutex_lock(®lock);
for (x = 0; x < SOME_PRIME; x++) {
@@ -928,7 +1044,7 @@
}
}
ast_mutex_unlock(®lock);
-
+
/* Dump the whole list */
for (cur = list; cur; cur = cur->next) {
len += cur->len;
@@ -936,18 +1052,18 @@
count += cur->count;
if (cur->cache_len) {
if (fn) {
- ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in function '%s' of '%s'\n",
+ ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in function '%s' of '%s'\n",
cur->len, cur->cache_len, cur->count, cur->fn, fn);
} else {
- ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in file '%s'\n",
+ ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in file '%s'\n",
cur->len, cur->cache_len, cur->count, cur->fn);
}
} else {
if (fn) {
- ast_cli(fd, "%10d bytes in %d allocations in function '%s' of '%s'\n",
+ ast_cli(fd, "%10d bytes in %d allocations in function '%s' of '%s'\n",
cur->len, cur->count, cur->fn, fn);
} else {
- ast_cli(fd, "%10d bytes in %d allocations in file '%s'\n",
+ ast_cli(fd, "%10d bytes in %d allocations in file '%s'\n",
cur->len, cur->count, cur->fn);
}
}
@@ -961,17 +1077,16 @@
return RESULT_SUCCESS;
}
-static char show_memory_help[] =
+static char show_memory_help[] =
"Usage: memory show allocations [<file>|anomolies]\n"
" Dumps a list of all segments of allocated memory, optionally\n"
"limited to those from a specific file\n";
-static char show_memory_summary_help[] =
+static char show_memory_summary_help[] =
"Usage: memory show summary [<file>]\n"
" Summarizes heap memory allocations by file, or optionally\n"
"by function, if a file is specified\n";
-#ifdef MALLOC_HOLD
static char memory_show_free_available_help[] =
"Usage: memory show {free|available|polluted}\n"
" Show memory pools in each of several states:\n"
@@ -980,7 +1095,6 @@
" available - Available for reallocation by another thread.\n"
" polluted - Used while in a 'free' state, and thus won't be released for\n"
" reuse.\n";
-#endif
static struct ast_cli_entry cli_show_memory_allocations_deprecated = {
{ "show", "memory", "allocations", NULL },
@@ -1001,7 +1115,6 @@
handle_show_memory_summary, "Summarize outstanding memory allocations",
show_memory_summary_help, NULL, &cli_show_memory_summary_deprecated },
-#ifdef MALLOC_HOLD
{ { "memory", "show", "free", NULL },
handle_memory_show_free_available, "Show memory in a freed stage",
memory_show_free_available_help, },
@@ -1013,7 +1126,6 @@
{ { "memory", "show", "polluted", NULL },
handle_memory_show_free_available, "Show memory removed from usage",
memory_show_free_available_help, },
-#endif
};
/*!
@@ -1025,7 +1137,6 @@
{
char filename[PATH_MAX];
size_t pad = sizeof(struct ast_region) - offsetof(struct ast_region, data);
-#ifdef MALLOC_HOLD
pthread_t notused;
struct sigaction sa = { .sa_flags = SA_SIGINFO | SA_NODEFER, .sa_sigaction = handle_sigsegv, };
@@ -1045,19 +1156,18 @@
ast_pthread_create_background(¬used, NULL, memory_destructor, NULL);
ast_pthread_create_background(¬used, NULL, memory_reporter, NULL);
-#endif
if (pad) {
ast_log(LOG_ERROR, "struct ast_region has %d bytes of padding! This must be eliminated for low-fence checking to work properly!\n", (int) pad);
}
ast_cli_register_multiple(cli_memory, sizeof(cli_memory) / sizeof(struct ast_cli_entry));
-
+
snprintf(filename, sizeof(filename), "%s/mmlog", (char *)ast_config_AST_LOG_DIR);
-
+
if (option_verbose)
ast_verbose("Asterisk Malloc Debugger Started (see %s))\n", filename);
-
+
if ((mmlog = fopen(filename, "a+"))) {
time_t now = time(NULL);
struct tm tm;
Modified: team/tilghman/malloc_hold/main/rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/malloc_hold/main/rtp.c?view=diff&rev=243116&r1=243115&r2=243116
==============================================================================
--- team/tilghman/malloc_hold/main/rtp.c (original)
+++ team/tilghman/malloc_hold/main/rtp.c Tue Jan 26 02:03:25 2010
@@ -25,6 +25,8 @@
*
* \note RTP is defined in RFC 3550.
*/
+
+#define MALLOC_HOLD 1
#include "asterisk.h"
More information about the svn-commits
mailing list