Skip to content
Snippets Groups Projects
Commit 11258c02 authored by Mark Spencer's avatar Mark Spencer
Browse files

Fix some astmm formatting and path issues (bug #4753)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6269 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 8712d1d7
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
* the GNU General Public License * the GNU General Public License
*/ */
#ifdef __AST_DEBUG_MALLOC #ifdef __AST_DEBUG_MALLOC
#include <malloc.h> #include <malloc.h>
...@@ -31,10 +29,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ...@@ -31,10 +29,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define SOME_PRIME 563 #define SOME_PRIME 563
#define FUNC_CALLOC 1 #define FUNC_CALLOC 1
#define FUNC_MALLOC 2 #define FUNC_MALLOC 2
#define FUNC_REALLOC 3 #define FUNC_REALLOC 3
#define FUNC_STRDUP 4 #define FUNC_STRDUP 4
#define FUNC_STRNDUP 5 #define FUNC_STRNDUP 5
#define FUNC_VASPRINTF 6 #define FUNC_VASPRINTF 6
...@@ -68,7 +66,7 @@ AST_MUTEX_DEFINE_STATIC(showmemorylock); ...@@ -68,7 +66,7 @@ AST_MUTEX_DEFINE_STATIC(showmemorylock);
static inline void *__ast_alloc_region(size_t size, int which, const char *file, int lineno, const char *func) static inline void *__ast_alloc_region(size_t size, int which, const char *file, int lineno, const char *func)
{ {
struct ast_region *reg; struct ast_region *reg;
void *ptr=NULL; void *ptr = NULL;
int hash; int hash;
reg = malloc(size + sizeof(struct ast_region)); reg = malloc(size + sizeof(struct ast_region));
ast_mutex_lock(&reglock); ast_mutex_lock(&reglock);
...@@ -104,7 +102,7 @@ static inline size_t __ast_sizeof_region(void *ptr) ...@@ -104,7 +102,7 @@ static inline size_t __ast_sizeof_region(void *ptr)
ast_mutex_lock(&reglock); ast_mutex_lock(&reglock);
reg = regions[hash]; reg = regions[hash];
while(reg) { while (reg) {
if (reg->data == ptr) { if (reg->data == ptr) {
len = reg->len; len = reg->len;
break; break;
...@@ -121,13 +119,13 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha ...@@ -121,13 +119,13 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
struct ast_region *reg, *prev = NULL; struct ast_region *reg, *prev = NULL;
ast_mutex_lock(&reglock); ast_mutex_lock(&reglock);
reg = regions[hash]; reg = regions[hash];
while(reg) { while (reg) {
if (reg->data == ptr) { if (reg->data == ptr) {
if (prev) if (prev) {
prev->next = reg->next; prev->next = reg->next;
else } else {
regions[hash] = reg->next; regions[hash] = reg->next;
}
break; break;
} }
prev = reg; prev = reg;
...@@ -137,11 +135,9 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha ...@@ -137,11 +135,9 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
if (reg) { if (reg) {
free(reg); free(reg);
} else { } else {
fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", ptr, func, file, lineno);
ptr, func, file, lineno);
if (mmlog) { if (mmlog) {
fprintf(mmlog, "%ld - WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", time(NULL), fprintf(mmlog, "%ld - WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
ptr, func, file, lineno);
fflush(mmlog); fflush(mmlog);
} }
} }
...@@ -169,15 +165,13 @@ void __ast_free(void *ptr, const char *file, int lineno, const char *func) ...@@ -169,15 +165,13 @@ 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) void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
{ {
void *tmp; void *tmp;
size_t len=0; size_t len = 0;
if (ptr) { if (ptr) {
len = __ast_sizeof_region(ptr); len = __ast_sizeof_region(ptr);
if (!len) { if (!len) {
fprintf(stderr, "WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", fprintf(stderr, "WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", ptr, func, file, lineno);
ptr, func, file, lineno);
if (mmlog) { if (mmlog) {
fprintf(mmlog, "%ld - WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", fprintf(mmlog, "%ld - WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
time(NULL), ptr, func, file, lineno);
fflush(mmlog); fflush(mmlog);
} }
return NULL; return NULL;
...@@ -232,10 +226,11 @@ int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, ...@@ -232,10 +226,11 @@ int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file,
n = vsnprintf(*strp, size, fmt, ap); n = vsnprintf(*strp, size, fmt, ap);
if (n > -1 && n < size) if (n > -1 && n < size)
return n; return n;
if (n > -1) /* glibc 2.1 */ if (n > -1) { /* glibc 2.1 */
size = n+1; size = n+1;
else /* glibc 2.0 */ } else { /* glibc 2.0 */
size *= 2; size *= 2;
}
if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL) if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL)
return -1; return -1;
} }
...@@ -246,17 +241,17 @@ static int handle_show_memory(int fd, int argc, char *argv[]) ...@@ -246,17 +241,17 @@ static int handle_show_memory(int fd, int argc, char *argv[])
char *fn = NULL; char *fn = NULL;
int x; int x;
struct ast_region *reg; struct ast_region *reg;
unsigned int len=0; unsigned int len = 0;
int count = 0; int count = 0;
if (argc >3) if (argc > 3)
fn = argv[3]; fn = argv[3];
/* try to lock applications list ... */ /* try to lock applications list ... */
ast_mutex_lock(&showmemorylock); ast_mutex_lock(&showmemorylock);
for (x=0;x<SOME_PRIME;x++) { for (x = 0; x < SOME_PRIME; x++) {
reg = regions[x]; reg = regions[x];
while(reg) { while (reg) {
if (!fn || !strcasecmp(fn, reg->file)) { if (!fn || !strcasecmp(fn, reg->file)) {
ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %s\n", reg->len, reg->func, reg->lineno, reg->file); ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %s\n", reg->len, reg->func, reg->lineno, reg->file);
len += reg->len; len += reg->len;
...@@ -282,22 +277,22 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[]) ...@@ -282,22 +277,22 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[])
char *fn = NULL; char *fn = NULL;
int x; int x;
struct ast_region *reg; struct ast_region *reg;
unsigned int len=0; unsigned int len = 0;
int count = 0; int count = 0;
struct file_summary *list = NULL, *cur; struct file_summary *list = NULL, *cur;
if (argc >3) if (argc > 3)
fn = argv[3]; fn = argv[3];
/* try to lock applications list ... */ /* try to lock applications list ... */
ast_mutex_lock(&reglock); ast_mutex_lock(&reglock);
for (x=0;x<SOME_PRIME;x++) { for (x = 0; x < SOME_PRIME; x++) {
reg = regions[x]; reg = regions[x];
while(reg) { while (reg) {
if (!fn || !strcasecmp(fn, reg->file)) { if (!fn || !strcasecmp(fn, reg->file)) {
cur = list; cur = list;
while(cur) { while (cur) {
if ((!fn && !strcmp(cur->fn, reg->file)) || (fn && !strcmp(cur->fn, reg->func))) if ((!fn && !strcmp(cur->fn, reg->file)) || (fn && !strcmp(cur->fn, reg->func)))
break; break;
cur = cur->next; cur = cur->next;
...@@ -318,14 +313,15 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[]) ...@@ -318,14 +313,15 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[])
ast_mutex_unlock(&reglock); ast_mutex_unlock(&reglock);
/* Dump the whole list */ /* Dump the whole list */
while(list) { while (list) {
cur = list; cur = list;
len += list->len; len += list->len;
count += list->count; count += list->count;
if (fn) if (fn) {
ast_cli(fd, "%10d bytes in %5d allocations in function '%s' of '%s'\n", list->len, list->count, list->fn, fn); ast_cli(fd, "%10d bytes in %5d allocations in function '%s' of '%s'\n", list->len, list->count, list->fn, fn);
else } else {
ast_cli(fd, "%10d bytes in %5d allocations in file '%s'\n", list->len, list->count, list->fn); ast_cli(fd, "%10d bytes in %5d allocations in file '%s'\n", list->len, list->count, list->fn);
}
list = list->next; list = list->next;
#if 0 #if 0
free(cur); free(cur);
...@@ -355,14 +351,16 @@ static struct ast_cli_entry show_memory_summary_cli = ...@@ -355,14 +351,16 @@ static struct ast_cli_entry show_memory_summary_cli =
handle_show_memory_summary, "Summarize outstanding memory allocations", handle_show_memory_summary, "Summarize outstanding memory allocations",
show_memory_summary_help }; show_memory_summary_help };
void __ast_mm_init(void) void __ast_mm_init(void)
{ {
char filename[80] = "";
ast_cli_register(&show_memory_allocations_cli); ast_cli_register(&show_memory_allocations_cli);
ast_cli_register(&show_memory_summary_cli); ast_cli_register(&show_memory_summary_cli);
mmlog = fopen("/var/log/asterisk/mmlog", "a+");
snprintf(filename, sizeof(filename), "%s/mmlog", (char *)ast_config_AST_LOG_DIR)
mmlog = fopen(filename, "a+");
if (option_verbose) if (option_verbose)
ast_verbose("Asterisk Malloc Debugger Started (see /var/log/asterisk/mmlog)\n"); ast_verbose("Asterisk Malloc Debugger Started (see %s))\n", filename);
if (mmlog) { if (mmlog) {
fprintf(mmlog, "%ld - New session\n", time(NULL)); fprintf(mmlog, "%ld - New session\n", time(NULL));
fflush(mmlog); fflush(mmlog);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment