Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv22048

Modified Files:
        astmm.c 
Log Message:
Fix some astmm formatting and path issues (bug #4753)


Index: astmm.c
===================================================================
RCS file: /usr/cvsroot/asterisk/astmm.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- astmm.c     10 Jul 2005 22:56:21 -0000      1.17
+++ astmm.c     3 Aug 2005 04:50:09 -0000       1.18
@@ -11,8 +11,6 @@
  * the GNU General Public License
  */
 
-
-
 #ifdef __AST_DEBUG_MALLOC
 
 #include <malloc.h>
@@ -31,10 +29,10 @@
 
 #define SOME_PRIME 563
 
-#define FUNC_CALLOC            1
-#define FUNC_MALLOC            2
+#define FUNC_CALLOC    1
+#define FUNC_MALLOC    2
 #define FUNC_REALLOC   3
-#define FUNC_STRDUP            4
+#define FUNC_STRDUP    4
 #define FUNC_STRNDUP   5
 #define FUNC_VASPRINTF 6
 
@@ -68,7 +66,7 @@
 static inline void *__ast_alloc_region(size_t size, int which, const char 
*file, int lineno, const char *func)
 {
        struct ast_region *reg;
-       void *ptr=NULL;
+       void *ptr = NULL;
        int hash;
        reg = malloc(size + sizeof(struct ast_region));
        ast_mutex_lock(&reglock);
@@ -104,7 +102,7 @@
        
        ast_mutex_lock(&reglock);
        reg = regions[hash];
-       while(reg) {
+       while (reg) {
                if (reg->data == ptr) {
                        len = reg->len;
                        break;
@@ -121,13 +119,13 @@
        struct ast_region *reg, *prev = NULL;
        ast_mutex_lock(&reglock);
        reg = regions[hash];
-       while(reg) {
+       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 @@
        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);
                }
        }
@@ -169,15 +165,13 @@
 void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, 
const char *func) 
 {
        void *tmp;
-       size_t len=0;
+       size_t len = 0;
        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 @@
                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;
        }
@@ -246,17 +241,17 @@
        char *fn = NULL;
        int x;
        struct ast_region *reg;
-       unsigned int len=0;
+       unsigned int len = 0;
        int count = 0;
-       if (argc >3) 
+       if (argc > 3) 
                fn = argv[3];
 
        /* try to lock applications list ... */
        ast_mutex_lock(&showmemorylock);
 
-       for (x=0;x<SOME_PRIME;x++) {
+       for (x = 0; x < SOME_PRIME; x++) {
                reg = regions[x];
-               while(reg) {
+               while (reg) {
                        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);
                                len += reg->len;
@@ -282,22 +277,22 @@
        char *fn = NULL;
        int x;
        struct ast_region *reg;
-       unsigned int len=0;
+       unsigned int len = 0;
        int count = 0;
        struct file_summary *list = NULL, *cur;
        
-       if (argc >3) 
+       if (argc > 3) 
                fn = argv[3];
 
        /* try to lock applications list ... */
        ast_mutex_lock(&reglock);
 
-       for (x=0;x<SOME_PRIME;x++) {
+       for (x = 0; x < SOME_PRIME; x++) {
                reg = regions[x];
-               while(reg) {
+               while (reg) {
                        if (!fn || !strcasecmp(fn, reg->file)) {
                                cur = list;
-                               while(cur) {
+                               while (cur) {
                                        if ((!fn && !strcmp(cur->fn, 
reg->file)) || (fn && !strcmp(cur->fn, reg->func)))
                                                break;
                                        cur = cur->next;
@@ -318,14 +313,15 @@
        ast_mutex_unlock(&reglock);
        
        /* Dump the whole list */
-       while(list) {
+       while (list) {
                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 @@
        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);

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to