[gs-cvs] rev 8690 - branches/mtrender/src

ray at ghostscript.com ray at ghostscript.com
Thu May 1 22:35:18 PDT 2008


Author: ray
Date: 2008-05-01 22:35:17 -0700 (Thu, 01 May 2008)
New Revision: 8690

Modified:
   branches/mtrender/src/gsmchunk.c
   branches/mtrender/src/gsmchunk.h
Log:
Add debug_dump facility to the chunk memory wrapper to allow for leak detection.
Also add a 'sequence' element to the object header in chunks so that a debugger
conditional breakpoint can be used to trigger on the allocation of a leaked
object.


Modified: branches/mtrender/src/gsmchunk.c
===================================================================
--- branches/mtrender/src/gsmchunk.c	2008-05-02 05:31:39 UTC (rev 8689)
+++ branches/mtrender/src/gsmchunk.c	2008-05-02 05:35:17 UTC (rev 8690)
@@ -79,6 +79,9 @@
     uint size;			/* objlist: client size */
     	/* if freelist: size of block (obj header and client area must fit in block) */
     gs_memory_type_ptr_t type;
+#ifdef DEBUG
+    unsigned long sequence;
+#endif
 } chunk_obj_node_t;
 
 /*
@@ -98,6 +101,9 @@
     gs_memory_common;		/* interface outside world sees */
     gs_memory_t *target;	/* base allocator */
     chunk_mem_node_t *head_chunk;
+#ifdef DEBUG
+    unsigned long sequence_counter;
+#endif
 } gs_memory_chunk_t;
 
 /* ---------- Public constructors/destructors ---------- */
@@ -119,6 +125,9 @@
     cmem->non_gc_memory = (gs_memory_t *)cmem;	/* and are not subject to GC */
     cmem->target = target;
     cmem->head_chunk = NULL;
+#ifdef DEBUG
+    cmem->sequence_counter = 0;
+#endif
 
     /* Init the chunk management values */
 
@@ -145,6 +154,30 @@
     return cmem->target;
 }
 
+#ifdef DEBUG
+void
+gs_memory_chunk_dump_memory(const gs_memory_t *mem)
+{
+    gs_memory_chunk_t *cmem = (gs_memory_chunk_t *)mem;
+    chunk_mem_node_t *head = cmem->head_chunk;
+    chunk_mem_node_t *current;
+    chunk_mem_node_t *next;
+
+    current = head;
+    while ( current != NULL ) { 
+	if (current->objlist != NULL) {
+	    chunk_obj_node_t *obj;
+
+	    for (obj= current->objlist; obj != NULL; obj=obj->next) 
+		dprintf4("chunk_mem leak, obj=0x%lx, size=%d, type=0x%lx, sequence#=%ld\n",
+			(ulong)obj, obj->size, (ulong)(obj->type), obj->sequence);
+	}
+	next = current->next; 
+	current = next;
+    }
+}
+#endif
+
 /* -------- Private members --------- */
 
 /* Note that all of the data is 'immovable' and is opaque to the base allocator */
@@ -296,7 +329,7 @@
             }
         }
         if ( !found ) {
-            dprintf1("FAIL freeing wild pointer freed address %x not found\n", (uint)addr );
+            dprintf1("FAIL freeing wild pointer freed address 0x%lx not found\n", (ulong)addr );
 	    return -1;
 	}
     }
@@ -366,8 +399,9 @@
     }
 
 #ifdef DEBUG
-memset((byte *)(newobj) + sizeof(chunk_obj_node_t), 0xa1, newsize - sizeof(chunk_obj_node_t));
-memset((byte *)(newobj) + sizeof(chunk_obj_node_t), 0xac, size);
+    memset((byte *)(newobj) + sizeof(chunk_obj_node_t), 0xa1, newsize - sizeof(chunk_obj_node_t));
+    memset((byte *)(newobj) + sizeof(chunk_obj_node_t), 0xac, size);
+    newobj->sequence = cmem->sequence_counter++;
 #endif
 
     newobj->next = current->objlist;	/* link to start of list */
@@ -480,7 +514,7 @@
 	}
 	if (current == NULL) {
 	    /* Object not found in any chunk */
-	    dprintf1("chunk_free_obj failed, object %0x not in any chunk\n", ((unsigned int)obj));
+	    dprintf1("chunk_free_obj failed, object 0x%lx not in any chunk\n", ((ulong)obj));
 	    return;
 	}
 
@@ -493,8 +527,8 @@
 	}
 	if (scan_obj == NULL) {
 	    /* Object not found in expected chunk */
-	    dprintf3("chunk_free_obj failed, object %0x not in chunk at %0x, size = %0x\n",
-			    ((unsigned int)obj), ((unsigned int)current), current->size);
+	    dprintf3("chunk_free_obj failed, object 0x%lx not in chunk at 0x%lx, size = %d\n",
+			    ((ulong)obj), ((ulong)current), current->size);
 	    return;
 	}
 	/* link around the object being freed */

Modified: branches/mtrender/src/gsmchunk.h
===================================================================
--- branches/mtrender/src/gsmchunk.h	2008-05-02 05:31:39 UTC (rev 8689)
+++ branches/mtrender/src/gsmchunk.h	2008-05-02 05:35:17 UTC (rev 8690)
@@ -32,5 +32,7 @@
 gs_memory_t *gs_memory_chunk_target(const gs_memory_t *cmem);
 
 #ifdef DEBUG
+void gs_memory_chunk_dump_memory(const gs_memory_t *mem);
+
 int chunk_allocator_unit_test(gs_memory_t *mem);
 #endif /* DEBUG */



More information about the gs-cvs mailing list