[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49179] trunk/blender/intern/guardedalloc/ intern/mallocn.c: Debug option for guarded allocation: store name of original datablock

Sergey Sharybin sergey.vfx at gmail.com
Tue Jul 24 17:17:03 CEST 2012


Revision: 49179
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49179
Author:   nazgul
Date:     2012-07-24 15:17:03 +0000 (Tue, 24 Jul 2012)
Log Message:
-----------
Debug option for guarded allocation: store name of original datablock
when using MEM_dupallocN. This helps figuring out issues with non-freed
dup_alloc blocks,

Simply enable DEBUG_MEMDUPLINAME in mallocn.c file.

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/intern/mallocn.c

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-24 13:02:54 UTC (rev 49178)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c	2012-07-24 15:17:03 UTC (rev 49179)
@@ -55,6 +55,14 @@
 #include "MEM_guardedalloc.h"
 
 /* Only for debugging:
+ * store original buffer's name when doing MEM_dupallocN
+ * helpful to profile issues with non-freed "dup_alloc" buffers,
+ * but this introduces some overhead to memory header and makes
+ * things slower a bit, so betterto keep disabled by default
+ */
+//#define DEBUG_MEMDUPLINAME
+
+/* Only for debugging:
  * lets you count the allocations so as to find the allocator of unfreed memory
  * in situations where the leak is predictable */
 
@@ -96,6 +104,10 @@
 #ifdef DEBUG_MEMCOUNTER
 	int _count;
 #endif
+
+#ifdef DEBUG_MEMDUPLINAME
+	int need_free_name, pad;
+#endif
 } MemHead;
 
 typedef struct MemTail {
@@ -243,14 +255,37 @@
 	if (vmemh) {
 		MemHead *memh = vmemh;
 		memh--;
-		
+
+#ifndef DEBUG_MEMDUPLINAME
 		if (memh->mmap)
 			newp = MEM_mapallocN(memh->len, "dupli_mapalloc");
 		else
 			newp = MEM_mallocN(memh->len, "dupli_alloc");
 
 		if (newp == NULL) return NULL;
+#else
+		{
+			MemHead *nmemh;
+			char *name = malloc(strlen(memh->name) + 24);
 
+			if (memh->mmap) {
+				sprintf(name, "%s %s", "dupli_mapalloc", memh->name);
+				newp = MEM_mapallocN(memh->len, name);
+			}
+			else {
+				sprintf(name, "%s %s", "dupli_alloc", memh->name);
+				newp = MEM_mallocN(memh->len, name);
+			}
+
+			if (newp == NULL) return NULL;
+
+			nmemh = newp;
+			nmemh--;
+
+			nmemh->need_free_name = 1;
+		}
+#endif
+
 		memcpy(newp, vmemh, memh->len);
 	}
 
@@ -289,6 +324,10 @@
 	memh->len = len;
 	memh->mmap = 0;
 	memh->tag2 = MEMTAG2;
+
+#ifdef DEBUG_MEMDUPLINAME
+	memh->need_free_name = 0;
+#endif
 	
 	memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + len);
 	memt->tag3 = MEMTAG3;
@@ -733,6 +772,11 @@
 	totblock--;
 	mem_in_use -= memh->len;
 
+#ifdef DEBUG_MEMDUPLINAME
+	if (memh->need_free_name)
+		free((char *) memh->name);
+#endif
+
 	if (memh->mmap) {
 		mmap_in_use -= memh->len;
 		if (munmap(memh, memh->len + sizeof(MemHead) + sizeof(MemTail)))




More information about the Bf-blender-cvs mailing list