[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26866] trunk/blender/intern/guardedalloc/ intern/mallocn.c: simple malloc counter for debugging.
Campbell Barton
ideasman42 at gmail.com
Sat Feb 13 14:09:06 CET 2010
Revision: 26866
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26866
Author: campbellbarton
Date: 2010-02-13 14:09:06 +0100 (Sat, 13 Feb 2010)
Log Message:
-----------
simple malloc counter for debugging. disabled so no functional change.
Use when memory isnt being freed to easily set a breakpoint the Nth allocation.
Modified Paths:
--------------
trunk/blender/intern/guardedalloc/intern/mallocn.c
Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c 2010-02-13 12:41:58 UTC (rev 26865)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c 2010-02-13 13:09:06 UTC (rev 26866)
@@ -48,6 +48,23 @@
#include "MEM_guardedalloc.h"
+/* Only for debugging:
+ * lets you count the allocations so as to find the allocator of unfreed memory
+ * in situations where the leak is pradictable */
+
+// #define DEBUG_MEMCOUNTER
+
+#ifdef DEBUG_MEMCOUNTER
+#define DEBUG_MEMCOUNTER_ERROR_VAL 0 /* set this to the value that isnt being freed */
+static int _mallocn_count = 0;
+
+/* breakpoint here */
+static void memcount_raise(const char *name)
+{
+ fprintf(stderr, "%s: memcount-leak, %d\n", name, _mallocn_count);
+}
+#endif
+
/* --------------------------------------------------------------------- */
/* Data definition */
/* --------------------------------------------------------------------- */
@@ -71,6 +88,9 @@
const char * nextname;
int tag2;
int mmap; /* if true, memory was mmapped */
+#ifdef DEBUG_MEMCOUNTER
+ int _count;
+#endif
} MemHead;
typedef struct MemTail {
@@ -283,6 +303,12 @@
mem_unlock_thread();
if(malloc_debug_memset && len)
memset(memh+1, 255, len);
+
+#ifdef DEBUG_MEMCOUNTER
+ memh->_count= _mallocn_count++;
+ if(_mallocn_count==DEBUG_MEMCOUNTER_ERROR_VAL)
+ memcount_raise("MEM_mallocN");
+#endif
return (++memh);
}
mem_unlock_thread();
@@ -303,6 +329,11 @@
if(memh) {
make_memhead_header(memh, len, str);
mem_unlock_thread();
+#ifdef DEBUG_MEMCOUNTER
+ memh->_count= _mallocn_count++;
+ if(_mallocn_count==DEBUG_MEMCOUNTER_ERROR_VAL)
+ memcount_raise("MEM_callocN");
+#endif
return (++memh);
}
mem_unlock_thread();
@@ -340,6 +371,11 @@
memh->mmap= 1;
mmap_in_use += len;
mem_unlock_thread();
+#ifdef DEBUG_MEMCOUNTER
+ memh->_count= _mallocn_count++;
+ if(_mallocn_count==DEBUG_MEMCOUNTER_ERROR_VAL)
+ memcount_raise("MEM_mapallocN");
+#endif
return (++memh);
}
else {
@@ -453,7 +489,11 @@
if (pydict) {
fprintf(stderr, "{'len':%i, 'name':'''%s''', 'pointer':'%p'},\\\n", membl->len, membl->name, membl+1);
} else {
+#ifdef DEBUG_MEMCOUNTER
+ print_error("%s len: %d %p, count: %d\n",membl->name,membl->len, membl+1, membl->_count);
+#else
print_error("%s len: %d %p\n",membl->name,membl->len, membl+1);
+#endif
}
if(membl->next)
membl= MEMNEXT(membl->next);
More information about the Bf-blender-cvs
mailing list