#include <stdio.h>
#include <string.h>
#include <pthread.h>
+#include <time.h>
#include <asterisk/cli.h>
+#include <asterisk/logger.h>
+#include <asterisk/options.h>
#define SOME_PRIME 563
#undef strndup
#undef free
+static FILE *mmlog;
+
static struct ast_region {
struct ast_region *next;
char file[40];
pthread_mutex_unlock(®lock);
if (!reg) {
fprintf(stderr, "Out of memory :(\n");
+ if (mmlog)
+ fprintf(stderr, "%ld - Out of memory\n", time(NULL));
}
return ptr;
}
pthread_mutex_unlock(®lock);
if (reg) {
free(reg);
- } else
+ } else {
fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n",
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)
if (!len) {
fprintf(stderr, "WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n",
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;
}
}
{
ast_cli_register(&show_memory_allocations_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