Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-10-03 18:44:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-10-03 18:44:33 +0400
commitf5eb8803583b96b605a3116ab00be138a90bb0c2 (patch)
treee76db7b479acac8d9e58dfea97ff979049819727 /source/blender/blenlib
parentc819fd4ee0b935dd88f2b516c4d49332af447f03 (diff)
freeing mempool elements now fills freed memory with --debug for debug builds.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_mempool.h4
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c16
2 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 88650719712..3fab77f2cb2 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -67,6 +67,10 @@ void **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr) ATTR_
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 {
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 8301a7df35b..067ddf91794 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -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 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
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 @@ void BLI_mempool_destroy(BLI_mempool *pool)
MEM_freeN(pool);
}
}
+
+#ifdef DEBUG
+void BLI_mempool_set_memory_debug(void)
+{
+ mempool_debug_memset = true;
+}
+#endif