[asterisk-commits] kpfleming: branch 1.4 r48987 - in /branches/1.4:
channels/ include/asterisk/ ...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Dec 27 11:29:14 MST 2006
Author: kpfleming
Date: Wed Dec 27 12:29:13 2006
New Revision: 48987
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48987
Log:
allow 'show memory' and 'show memory summary' to distinguish memory allocations that were done for caching purposes, so they don't look like memory leaks
Modified:
branches/1.4/channels/iax2-parser.c
branches/1.4/include/asterisk/astmm.h
branches/1.4/include/asterisk/utils.h
branches/1.4/main/astmm.c
branches/1.4/main/frame.c
Modified: branches/1.4/channels/iax2-parser.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/iax2-parser.c?view=diff&rev=48987&r1=48986&r2=48987
==============================================================================
--- branches/1.4/channels/iax2-parser.c (original)
+++ branches/1.4/channels/iax2-parser.c Wed Dec 27 12:29:13 2006
@@ -957,7 +957,7 @@
}
if (!fr) {
- if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
+ if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
return NULL;
fr->mallocd_datalen = datalen;
}
Modified: branches/1.4/include/asterisk/astmm.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/astmm.h?view=diff&rev=48987&r1=48986&r2=48987
==============================================================================
--- branches/1.4/include/asterisk/astmm.h (original)
+++ branches/1.4/include/asterisk/astmm.h Wed Dec 27 12:29:13 2006
@@ -44,6 +44,7 @@
#undef vasprintf
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);
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);
@@ -58,6 +59,9 @@
/* Provide our own definitions */
#define 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__)
Modified: branches/1.4/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/utils.h?view=diff&rev=48987&r1=48986&r2=48987
==============================================================================
--- branches/1.4/include/asterisk/utils.h (original)
+++ branches/1.4/include/asterisk/utils.h Wed Dec 27 12:29:13 2006
@@ -362,6 +362,19 @@
)
/*!
+ * \brief A wrapper for calloc() for use in cache pools
+ *
+ * ast_calloc_cache() is a wrapper for calloc() that will generate an Asterisk log
+ * message in the case that the allocation fails. When memory debugging is in use,
+ * the memory allocated by this function will be marked as 'cache' so it can be
+ * distinguished from normal memory allocations.
+ *
+ * The arguments and return value are the same as calloc()
+ */
+#define ast_calloc_cache(num, len) \
+ _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+/*!
* \brief A wrapper for realloc()
*
* ast_realloc() is a wrapper for realloc() that will generate an Asterisk log
Modified: branches/1.4/main/astmm.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/astmm.c?view=diff&rev=48987&r1=48986&r2=48987
==============================================================================
--- branches/1.4/main/astmm.c (original)
+++ branches/1.4/main/astmm.c Wed Dec 27 12:29:13 2006
@@ -72,6 +72,7 @@
char func[40];
unsigned int lineno;
enum func_type which;
+ unsigned int cache; /* region was allocated as part of a cache pool */
size_t len;
unsigned int fence;
unsigned char data[0];
@@ -92,7 +93,7 @@
} \
} while (0)
-static inline void *__ast_alloc_region(size_t size, const enum func_type which, const char *file, int lineno, const char *func)
+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;
void *ptr = NULL;
@@ -101,7 +102,7 @@
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);
+ "at line %d of %s\n", (int) size, func, lineno, file);
}
ast_copy_string(reg->file, file, sizeof(reg->file));
@@ -109,6 +110,7 @@
reg->lineno = lineno;
reg->len = size;
reg->which = which;
+ reg->cache = cache;
ptr = reg->data;
hash = HASH(ptr);
reg->fence = FENCE_MAGIC;
@@ -181,15 +183,25 @@
{
void *ptr;
- if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func)))
+ 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 *ptr;
+
+ if ((ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func, 1)))
+ memset(ptr, 0, size * nmemb);
+
+ return ptr;
+}
+
void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)
{
- return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func);
+ return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func, 0);
}
void __ast_free(void *ptr, const char *file, int lineno, const char *func)
@@ -208,7 +220,7 @@
return NULL;
}
- if (!(tmp = __ast_alloc_region(size, FUNC_REALLOC, file, lineno, func)))
+ if (!(tmp = __ast_alloc_region(size, FUNC_REALLOC, file, lineno, func, 0)))
return NULL;
if (len > size)
@@ -230,7 +242,7 @@
return NULL;
len = strlen(s) + 1;
- if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func)))
+ if ((ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func, 0)))
strcpy(ptr, s);
return ptr;
@@ -247,7 +259,7 @@
len = strlen(s) + 1;
if (len > n)
len = n;
- if ((ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func)))
+ if ((ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func, 0)))
strcpy(ptr, s);
return ptr;
@@ -264,7 +276,7 @@
va_copy(ap2, ap);
size = vsnprintf(&s, 1, fmt, ap2);
va_end(ap2);
- if (!(*strp = __ast_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func))) {
+ if (!(*strp = __ast_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func, 0))) {
va_end(ap);
return -1;
}
@@ -284,7 +296,7 @@
va_copy(ap2, ap);
size = vsnprintf(&s, 1, fmt, ap2);
va_end(ap2);
- if (!(*strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func))) {
+ if (!(*strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func, 0))) {
va_end(ap);
return -1;
}
@@ -299,6 +311,7 @@
struct ast_region *reg;
unsigned int x;
unsigned int len = 0;
+ unsigned int cache_len = 0;
unsigned int count = 0;
unsigned int *fence;
@@ -321,16 +334,22 @@
}
}
if (!fn || !strcasecmp(fn, reg->file)) {
- ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %s\n",
- (int) reg->len, reg->func, reg->lineno, reg->file);
+ ast_cli(fd, "%10d bytes allocated%s in %20s at line %5d of %s\n",
+ (int) reg->len, reg->cache ? " (cache)" : "",
+ reg->func, reg->lineno, reg->file);
len += reg->len;
+ if (reg->cache)
+ cache_len += reg->len;
count++;
}
}
}
ast_mutex_unlock(&showmemorylock);
- ast_cli(fd, "%d bytes allocated %d units total\n", len, count);
+ if (cache_len)
+ ast_cli(fd, "%d bytes allocated (%d in caches) in %d allocations", len, cache_len, count);
+ else
+ ast_cli(fd, "%d bytes allocated in %d allocations\n", len, count);
return RESULT_SUCCESS;
}
@@ -341,10 +360,12 @@
int x;
struct ast_region *reg;
unsigned int len = 0;
+ unsigned int cache_len = 0;
int count = 0;
struct file_summary {
char fn[80];
int len;
+ int cache_len;
int count;
struct file_summary *next;
} *list = NULL, *cur;
@@ -371,6 +392,8 @@
}
cur->len += reg->len;
+ if (reg->cache)
+ cur->cache_len += reg->len;
cur->count++;
}
}
@@ -379,17 +402,31 @@
/* Dump the whole list */
for (cur = list; cur; cur = cur->next) {
len += cur->len;
+ cache_len += cur->cache_len;
count += cur->count;
- if (fn) {
- ast_cli(fd, "%10d bytes in %5d allocations in function '%s' of '%s'\n",
- cur->len, cur->count, cur->fn, fn);
+ if (cur->cache_len) {
+ if (fn) {
+ 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",
+ cur->len, cur->cache_len, cur->count, cur->fn);
+ }
} else {
- ast_cli(fd, "%10d bytes in %5d allocations in file '%s'\n",
- cur->len, cur->count, cur->fn);
- }
- }
-
- ast_cli(fd, "%d bytes allocated %d units total\n", len, count);
+ if (fn) {
+ 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",
+ cur->len, cur->count, cur->fn);
+ }
+ }
+ }
+
+ if (cache_len)
+ ast_cli(fd, "%d bytes allocated (%d in caches) in %d allocations", len, cache_len, count);
+ else
+ ast_cli(fd, "%d bytes allocated in %d allocations\n", len, count);
return RESULT_SUCCESS;
}
Modified: branches/1.4/main/frame.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/frame.c?view=diff&rev=48987&r1=48986&r2=48987
==============================================================================
--- branches/1.4/main/frame.c (original)
+++ branches/1.4/main/frame.c Wed Dec 27 12:29:13 2006
@@ -297,7 +297,7 @@
}
}
- if (!(f = ast_calloc(1, sizeof(*f))))
+ if (!(f = ast_calloc_cache(1, sizeof(*f))))
return NULL;
f->mallocd_hdr_len = sizeof(*f);
@@ -454,7 +454,7 @@
AST_LIST_TRAVERSE_SAFE_END
}
if (!buf) {
- if (!(buf = ast_calloc(1, len)))
+ if (!(buf = ast_calloc_cache(1, len)))
return NULL;
out = buf;
out->mallocd_hdr_len = len;
More information about the asterisk-commits
mailing list