mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 12:20:12 +00:00
Write to memory management log
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@963 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
2
Makefile
2
Makefile
@@ -49,7 +49,7 @@ TRACE_FRAMES = #-DTRACE_FRAMES
|
|||||||
# *CLI> show memory allocations [filename]
|
# *CLI> show memory allocations [filename]
|
||||||
# *CLI> show memory summary [filename]
|
# *CLI> show memory summary [filename]
|
||||||
#
|
#
|
||||||
MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
|
MALLOC_DEBUG = -include $(PWD)/include/asterisk/astmm.h
|
||||||
|
|
||||||
# Where to install asterisk after compiling
|
# Where to install asterisk after compiling
|
||||||
# Default -> leave empty
|
# Default -> leave empty
|
||||||
|
21
astmm.c
21
astmm.c
@@ -19,7 +19,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <time.h>
|
||||||
#include <asterisk/cli.h>
|
#include <asterisk/cli.h>
|
||||||
|
#include <asterisk/logger.h>
|
||||||
|
#include <asterisk/options.h>
|
||||||
|
|
||||||
#define SOME_PRIME 563
|
#define SOME_PRIME 563
|
||||||
|
|
||||||
@@ -37,6 +40,8 @@
|
|||||||
#undef strndup
|
#undef strndup
|
||||||
#undef free
|
#undef free
|
||||||
|
|
||||||
|
static FILE *mmlog;
|
||||||
|
|
||||||
static struct ast_region {
|
static struct ast_region {
|
||||||
struct ast_region *next;
|
struct ast_region *next;
|
||||||
char file[40];
|
char file[40];
|
||||||
@@ -75,6 +80,8 @@ static inline void *__ast_alloc_region(size_t size, int which, const char *file,
|
|||||||
pthread_mutex_unlock(®lock);
|
pthread_mutex_unlock(®lock);
|
||||||
if (!reg) {
|
if (!reg) {
|
||||||
fprintf(stderr, "Out of memory :(\n");
|
fprintf(stderr, "Out of memory :(\n");
|
||||||
|
if (mmlog)
|
||||||
|
fprintf(stderr, "%ld - Out of memory\n", time(NULL));
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@@ -119,9 +126,13 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
|
|||||||
pthread_mutex_unlock(®lock);
|
pthread_mutex_unlock(®lock);
|
||||||
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)
|
||||||
|
fprintf(mmlog, "%ld - WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", time(NULL),
|
||||||
|
ptr, func, file, lineno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -152,6 +163,9 @@ void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const
|
|||||||
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)
|
||||||
|
fprintf(mmlog, "%ld - WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n",
|
||||||
|
time(NULL), ptr, func, file, lineno);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,6 +328,11 @@ void __ast_mm_init(void)
|
|||||||
{
|
{
|
||||||
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+");
|
||||||
|
if (option_verbose)
|
||||||
|
ast_verbose("Asterisk Malloc Debugger Started (see /var/log/mmlog)\n");
|
||||||
|
if (mmlog)
|
||||||
|
fprintf(mmlog, "%ld - New session\n", time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user