forked from bartvdbraak/blender
freeing mempool elements now fills freed memory with --debug for debug builds.
This commit is contained in:
parent
c819fd4ee0
commit
f5eb880358
@ -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_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);
|
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 **/
|
/** iteration stuff. note: this may easy to produce bugs with **/
|
||||||
/* private structure */
|
/* private structure */
|
||||||
typedef struct BLI_mempool_iter {
|
typedef struct BLI_mempool_iter {
|
||||||
|
@ -66,6 +66,10 @@
|
|||||||
/* when undefined, merge the allocs for BLI_mempool_chunk and its data */
|
/* when undefined, merge the allocs for BLI_mempool_chunk and its data */
|
||||||
// #define USE_DATA_PTR
|
// #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
|
* 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.
|
* #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");
|
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
|
#endif
|
||||||
|
|
||||||
if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
|
if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
|
||||||
@ -609,3 +618,10 @@ void BLI_mempool_destroy(BLI_mempool *pool)
|
|||||||
MEM_freeN(pool);
|
MEM_freeN(pool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
void BLI_mempool_set_memory_debug(void)
|
||||||
|
{
|
||||||
|
mempool_debug_memset = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -76,13 +76,13 @@
|
|||||||
#include "BLI_threads.h"
|
#include "BLI_threads.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
#include "BLI_callbacks.h"
|
#include "BLI_callbacks.h"
|
||||||
|
#include "BLI_blenlib.h"
|
||||||
|
#include "BLI_mempool.h"
|
||||||
|
|
||||||
#include "DNA_ID.h"
|
#include "DNA_ID.h"
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
#include "DNA_userdef_types.h"
|
#include "DNA_userdef_types.h"
|
||||||
|
|
||||||
#include "BLI_blenlib.h"
|
|
||||||
|
|
||||||
#include "BKE_blender.h"
|
#include "BKE_blender.h"
|
||||||
#include "BKE_brush.h"
|
#include "BKE_brush.h"
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
@ -412,10 +412,13 @@ static int debug_mode(int UNUSED(argc), const char **UNUSED(argv), void *data)
|
|||||||
G.debug |= G_DEBUG; /* std output printf's */
|
G.debug |= G_DEBUG; /* std output printf's */
|
||||||
printf(BLEND_VERSION_STRING_FMT);
|
printf(BLEND_VERSION_STRING_FMT);
|
||||||
MEM_set_memory_debug();
|
MEM_set_memory_debug();
|
||||||
|
#ifdef DEBUG
|
||||||
|
BLI_mempool_set_memory_debug();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_BUILDINFO
|
#ifdef WITH_BUILDINFO
|
||||||
printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
|
printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
|
||||||
#endif // WITH_BUILDINFO
|
#endif
|
||||||
|
|
||||||
BLI_argsPrint(data);
|
BLI_argsPrint(data);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user