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
This commit is contained in:
Mark Spencer
2005-08-03 04:50:09 +00:00
parent 8712d1d7f1
commit 11258c02cb

38
astmm.c
View File

@@ -11,8 +11,6 @@
* the GNU General Public License
*/
#ifdef __AST_DEBUG_MALLOC
#include <malloc.h>
@@ -123,11 +121,11 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
reg = regions[hash];
while (reg) {
if (reg->data == ptr) {
if (prev)
if (prev) {
prev->next = reg->next;
else
} else {
regions[hash] = reg->next;
}
break;
}
prev = reg;
@@ -137,11 +135,9 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
if (reg) {
free(reg);
} else {
fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n",
ptr, func, file, lineno);
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);
fprintf(mmlog, "%ld - WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
fflush(mmlog);
}
}
@@ -173,11 +169,9 @@ void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const
if (ptr) {
len = __ast_sizeof_region(ptr);
if (!len) {
fprintf(stderr, "WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n",
ptr, func, file, lineno);
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);
fprintf(mmlog, "%ld - WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
fflush(mmlog);
}
return NULL;
@@ -232,10 +226,11 @@ int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file,
n = vsnprintf(*strp, size, fmt, ap);
if (n > -1 && n < size)
return n;
if (n > -1) /* glibc 2.1 */
if (n > -1) { /* glibc 2.1 */
size = n+1;
else /* glibc 2.0 */
} else { /* glibc 2.0 */
size *= 2;
}
if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL)
return -1;
}
@@ -322,10 +317,11 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[])
cur = list;
len += list->len;
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);
else
} else {
ast_cli(fd, "%10d bytes in %5d allocations in file '%s'\n", list->len, list->count, list->fn);
}
list = list->next;
#if 0
free(cur);
@@ -355,14 +351,16 @@ static struct ast_cli_entry show_memory_summary_cli =
handle_show_memory_summary, "Summarize outstanding memory allocations",
show_memory_summary_help };
void __ast_mm_init(void)
{
char filename[80] = "";
ast_cli_register(&show_memory_allocations_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)
ast_verbose("Asterisk Malloc Debugger Started (see /var/log/asterisk/mmlog)\n");
ast_verbose("Asterisk Malloc Debugger Started (see %s))\n", filename);
if (mmlog) {
fprintf(mmlog, "%ld - New session\n", time(NULL));
fflush(mmlog);