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 16:22:44 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-10-03 16:22:44 +0400
commit9b1be7ce93b8c40bac0da2743009399f732801a8 (patch)
treed6681596c60c4a5cebd0c32fc1b69d0d6f74cd57 /source/blender/blenlib/intern/BLI_mempool.c
parent6b2e56392470d401a6876ff036f6336602c30010 (diff)
add cmake option WITH_MEM_VALGRIND, helps to track down errors with mempool use which sometimes only show up as bugs in very rare cases (because even though the element is freed, the chunk is still allocated).
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index febf09745fb..8301a7df35b 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -45,6 +45,9 @@
#include "BLI_strict_flags.h" /* keep last */
+#ifdef WITH_MEM_VALGRIND
+# include "valgrind/memcheck.h"
+#endif
/* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */
#ifdef __BIG_ENDIAN__
@@ -275,6 +278,10 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem,
lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
}
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_CREATE_MEMPOOL(pool, 0, false);
+#endif
+
return pool;
}
@@ -297,6 +304,11 @@ void *BLI_mempool_alloc(BLI_mempool *pool)
}
pool->free = pool->free->next;
+
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_ALLOC(pool, retval, pool->esize);
+#endif
+
return retval;
}
@@ -367,6 +379,10 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
}
curnode->next = NULL; /* terminate the list */
}
+
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_FREE(pool, addr);
+#endif
}
int BLI_mempool_count(BLI_mempool *pool)
@@ -582,6 +598,10 @@ void BLI_mempool_destroy(BLI_mempool *pool)
{
mempool_chunk_free_all(&pool->chunks, pool->flag);
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_DESTROY_MEMPOOL(pool);
+#endif
+
if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
free(pool);
}