[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60531] trunk/blender/source: freeing mempool elements now fills freed memory with --debug for debug builds .

Campbell Barton ideasman42 at gmail.com
Thu Oct 3 16:44:33 CEST 2013


Revision: 60531
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60531
Author:   campbellbarton
Date:     2013-10-03 14:44:33 +0000 (Thu, 03 Oct 2013)
Log Message:
-----------
freeing mempool elements now fills freed memory with --debug for debug builds.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_mempool.h
    trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h	2013-10-03 14:24:54 UTC (rev 60530)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h	2013-10-03 14:44:33 UTC (rev 60531)
@@ -67,6 +67,10 @@
 void        BLI_mempool_as_array(BLI_mempool *pool, void *data) ATTR_NONNULL(1, 2);
 void       *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
 
+#ifdef DEBUG
+void        BLI_mempool_set_memory_debug(void);
+#endif
+
 /** iteration stuff.  note: this may easy to produce bugs with **/
 /* private structure */
 typedef struct BLI_mempool_iter {

Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2013-10-03 14:24:54 UTC (rev 60530)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2013-10-03 14:44:33 UTC (rev 60531)
@@ -66,6 +66,10 @@
 /* when undefined, merge the allocs for BLI_mempool_chunk and its data */
 // #define USE_DATA_PTR
 
+#ifdef DEBUG
+static bool mempool_debug_memset = false;
+#endif
+
 /**
  * A free element from #BLI_mempool_chunk. Data is cast to this type and stored in
  * #BLI_mempool.free as a single linked list, each item #BLI_mempool.esize large.
@@ -342,6 +346,11 @@
 			BLI_assert(!"Attempt to free data which is not in pool.\n");
 		}
 	}
+
+	/* enable for debugging */
+	if (UNLIKELY(mempool_debug_memset)) {
+		memset(addr, 255, pool->esize);
+	}
 #endif
 
 	if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
@@ -609,3 +618,10 @@
 		MEM_freeN(pool);
 	}
 }
+
+#ifdef DEBUG
+void BLI_mempool_set_memory_debug(void)
+{
+	mempool_debug_memset = true;
+}
+#endif

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2013-10-03 14:24:54 UTC (rev 60530)
+++ trunk/blender/source/creator/creator.c	2013-10-03 14:44:33 UTC (rev 60531)
@@ -76,13 +76,13 @@
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 #include "BLI_callbacks.h"
+#include "BLI_blenlib.h"
+#include "BLI_mempool.h"
 
 #include "DNA_ID.h"
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 
-#include "BLI_blenlib.h"
-
 #include "BKE_blender.h"
 #include "BKE_brush.h"
 #include "BKE_context.h"
@@ -412,10 +412,13 @@
 	G.debug |= G_DEBUG;  /* std output printf's */
 	printf(BLEND_VERSION_STRING_FMT);
 	MEM_set_memory_debug();
+#ifdef DEBUG
+	BLI_mempool_set_memory_debug();
+#endif
 
 #ifdef WITH_BUILDINFO
 	printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
-#endif // WITH_BUILDINFO
+#endif
 
 	BLI_argsPrint(data);
 	return 0;




More information about the Bf-blender-cvs mailing list