This is a multi-part message in MIME format.
--------------2AC5571D47A276016626084A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Yet another addition in the memory map/trace/leak detection searies.
This patch updates the last patch (leak detection). The change is that
the memory map is printed as a tree which greatly simplifies pinpointing
which structures that aren't freed properly.
/Henrik
--------------2AC5571D47A276016626084A
Content-Type: text/plain; charset=us-ascii; name="squid-1.2.beta14.memory_map_tree.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="squid-1.2.beta14.memory_map_tree.patch"
Index: squid/src/main.c
diff -u squid/src/main.c:1.1.1.11.2.2 squid/src/main.c:1.1.1.11.2.3
--- squid/src/main.c:1.1.1.11.2.2	Sun Feb  8 08:23:56 1998
+++ squid/src/main.c	Mon Feb  9 00:30:50 1998
@@ -749,9 +749,7 @@
     {
     extern int xmalloc_total;
     extern void xmalloc_find_leaks(void);
-    extern void xmalloc_dump_map(void);
     xmalloc_find_leaks();
-    xmalloc_dump_map();
     debug(1, 0) ("Memory used after shutdown: %d\n",xmalloc_total);
     }
 #endif
Index: squid/lib/util.c
===================================================================
RCS file: /usr/src/CVS/squid/lib/util.c,v
retrieving revision 1.1.1.7.2.3
retrieving revision 1.1.1.7.2.5
diff -u -r1.1.1.7.2.3 -r1.1.1.7.2.5
--- util.c	1998/02/08 07:38:46	1.1.1.7.2.3
+++ util.c	1998/02/09 00:12:49	1.1.1.7.2.5
@@ -355,62 +355,66 @@
     last_accounted = accounted;
     last_mallinfo = mi;
 }
-short (*malloc_refs)[DBG_ARRY_SZ];
-char **xmalloc_leak_test;
-#define XMALLOC_LEAK_CHECKED (1<<15)
+int malloc_refs[DBG_ARRY_BKTS][DBG_ARRY_SZ];
 #define XMALLOC_LEAK_ALIGN (4)
-static int xmalloc_scan_region(void *start, int size)
+static void xmalloc_scan_region(void *start, int size, int depth)
 {
     int B,I;
     char *ptr=start;
     char *end=ptr+size-XMALLOC_LEAK_ALIGN;
-    int found=0;
+    static int sum=0;
     while(ptr <= end) {
         void *p=*(void **)ptr;
         if (p && p!=start) {
             B = (((int) p) >> 4) & 0xFF;
             for (I = 0; I < DBG_ARRY_SZ; I++) {
                 if (malloc_ptrs[B][I] == p) {
-		    if (!malloc_refs[B][I])
-			found++;
-			malloc_refs[B][I]++;
+		    if (!malloc_refs[B][I]++) {
+			/* A new reference */
+			fprintf(stderr, "%*s%p %s:%d size %d allocation %d\n",
+			    depth,"",
+			    malloc_ptrs[B][I], malloc_file[B][I],
+			    malloc_line[B][I], malloc_size[B][I],
+			    malloc_count[B][I]);
+			sum += malloc_size[B][I];
+			xmalloc_scan_region(malloc_ptrs[B][I], malloc_size[B][I], depth+1);
+			if (depth == 0) {
+			    if ( sum != malloc_size[B][I] )
+				fprintf(stderr, "=== %d bytes\n", sum);
+			    sum=0;
+			}
+#if XMALLOC_SHOW_ALL_REFERENCES
+		    } else {
+			/* We have already scanned this pointer... */
+			fprintf(stderr, "%*s%p %s:%d size %d allocation %d ... (%d)\n",
+			    depth*2,"",
+			    malloc_ptrs[B][I], malloc_file[B][I],
+			    malloc_line[B][I], malloc_size[B][I],
+			    malloc_count[B][I], malloc_refs[B][I]);
+#endif
+		    }
                 }
-	    }	    
+	    }
         }
         ptr+=XMALLOC_LEAK_ALIGN;
     }
-    return found;
 }
 extern void _etext;
 void xmalloc_find_leaks(void)
 {
     int B,I;
-    int found;
     int leak_sum=0;
-    fprintf(stderr,"Searching for memory references...\n");
-    malloc_refs=xcalloc(DBG_ARRY_BKTS,sizeof(*malloc_refs));
-    found=xmalloc_scan_region(&_etext,(void *)sbrk(0)-(void *)&_etext);
-    while(found) {
-	found=0;
-	for(I=0;I<DBG_ARRY_SZ && !found;I++) {
-	    for(B=0;B<DBG_ARRY_BKTS;B++) {
-		if (malloc_refs[B][I] > 0) {
-		    malloc_refs[B][I] |= XMALLOC_LEAK_CHECKED;
-		    found+=xmalloc_scan_region(malloc_ptrs[B][I],
-			    malloc_size[B][I]);
-		}
-	    }
-	}
-    }
+    fprintf(stderr, "----- Memory map ----\n");
+    xmalloc_scan_region(&_etext,(void *)sbrk(0)-(void *)&_etext,0);
     for(B=0;B<DBG_ARRY_BKTS;B++) {
         for(I=0;I<DBG_ARRY_SZ;I++) {
-	    if (malloc_ptrs[B][I] && malloc_refs[B][I] == 0) {
+	    if (malloc_ptrs[B][I] && !malloc_refs[B][I] ) {
                 /* Found a leak... */
                 fprintf(stderr, "Leak found: %p",malloc_ptrs[B][I]);
                 fprintf(stderr, " %s",malloc_file[B][I]);
                 fprintf(stderr, ":%d",malloc_line[B][I]);
-		fprintf(stderr, " size %d\n",malloc_size[B][I]);
-		fprintf(stderr, " allocation %d",malloc_count[B][I]);
+		fprintf(stderr, " size %d",malloc_size[B][I]);
+		fprintf(stderr, " allocation %d\n",malloc_count[B][I]);
                 leak_sum += malloc_size[B][I];
             }
         }
@@ -419,21 +423,6 @@
         fprintf(stderr, "Total leaked memory: %d\n",leak_sum);
     } else {
         fprintf(stderr, "No memory leaks detected\n");
-    }
-}
-void xmalloc_dump_map(void)
-{
-    int B,I;
-    fprintf(stderr, "----- Memory map ----\n");
-    for(B=0;B<DBG_ARRY_BKTS;B++) {
-	for(I=0;I<DBG_ARRY_SZ;I++) {
-	    if (malloc_ptrs[B][I]) {
-		printf("%p %s:%d size %d allocation %d references %d\n",
-		    malloc_ptrs[B][I], malloc_file[B][I], malloc_line[B][I],
-		    malloc_size[B][I], malloc_count[B][I],
-		    malloc_refs[B][I]&(XMALLOC_LEAK_CHECKED-1));
-	    }
-	}
     }
     fprintf(stderr,"----------------------\n");
 }
Index: squid/snmplib/parse.c
diff -u squid/snmplib/parse.c:1.1.1.5 squid/snmplib/parse.c:1.1.1.5.2.1
--- squid/snmplib/parse.c:1.1.1.5	Sun Feb  8 02:24:48 1998
+++ squid/snmplib/parse.c	Mon Feb  9 01:13:06 1998
@@ -270,6 +270,7 @@
     }
 }
 
+#if NOT_USED
 static char *
 Malloc(unsigned int num)
 {
@@ -279,6 +280,9 @@
         num = 16;
     return xcalloc(1, num);
 }
+#else
+#define Malloc(n) xcalloc(1,(n))
+#endif
 
 static void
 print_error(char *string, char *token, int type)
--------------2AC5571D47A276016626084A--
Received on Tue Jul 29 2003 - 13:15:46 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:42 MST