mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-27 22:50:42 +00:00
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:
38
astmm.c
38
astmm.c
@@ -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>
|
||||||
@@ -123,11 +121,11 @@ static void __ast_free_region(void *ptr, const char *file, int lineno, const cha
|
|||||||
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
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,11 +169,9 @@ void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const
|
|||||||
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,
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -322,10 +317,11 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[])
|
|||||||
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 =
|
|||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user