mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-01-14 00:27:59 +08:00
track free blocks in valgrind for heap_destroy as well
This commit is contained in:
parent
82c85d1a13
commit
465eb81d30
@ -24,8 +24,9 @@ uses the block start pointer and original size (corresponding to the `mi_track_m
|
||||
|
||||
#if MI_VALGRIND
|
||||
|
||||
#define MI_TRACK_ENABLED 1
|
||||
#define MI_TRACK_TOOL "valgrind"
|
||||
#define MI_TRACK_ENABLED 1
|
||||
#define MI_TRACK_HEAP_DESTROY 1 // track free of individual blocks on heap_destroy
|
||||
#define MI_TRACK_TOOL "valgrind"
|
||||
|
||||
#include <valgrind/valgrind.h>
|
||||
#include <valgrind/memcheck.h>
|
||||
@ -39,8 +40,9 @@ uses the block start pointer and original size (corresponding to the `mi_track_m
|
||||
|
||||
#elif MI_ASAN
|
||||
|
||||
#define MI_TRACK_ENABLED 1
|
||||
#define MI_TRACK_TOOL "asan"
|
||||
#define MI_TRACK_ENABLED 1
|
||||
#define MI_TRACK_HEAP_DESTROY 0
|
||||
#define MI_TRACK_TOOL "asan"
|
||||
|
||||
#include <sanitizer/asan_interface.h>
|
||||
|
||||
@ -52,8 +54,9 @@ uses the block start pointer and original size (corresponding to the `mi_track_m
|
||||
|
||||
#else
|
||||
|
||||
#define MI_TRACK_ENABLED 0
|
||||
#define MI_TRACK_TOOL "none"
|
||||
#define MI_TRACK_ENABLED 0
|
||||
#define MI_TRACK_HEAP_DESTROY 0
|
||||
#define MI_TRACK_TOOL "none"
|
||||
|
||||
#define mi_track_malloc_size(p,reqsize,size,zero)
|
||||
#define mi_track_free_size(p,_size)
|
||||
|
11
src/heap.c
11
src/heap.c
@ -8,6 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
#include "mimalloc.h"
|
||||
#include "mimalloc-internal.h"
|
||||
#include "mimalloc-atomic.h"
|
||||
#include "mimalloc-track.h"
|
||||
|
||||
#include <string.h> // memset, memcpy
|
||||
|
||||
@ -310,6 +311,12 @@ void _mi_heap_destroy_pages(mi_heap_t* heap) {
|
||||
mi_heap_reset_pages(heap);
|
||||
}
|
||||
|
||||
static bool mi_cdecl mi_heap_track_block_free(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg) {
|
||||
MI_UNUSED(heap); MI_UNUSED(area); MI_UNUSED(arg); MI_UNUSED(block_size);
|
||||
mi_track_free_size(block,mi_usable_size(block));
|
||||
return true;
|
||||
}
|
||||
|
||||
void mi_heap_destroy(mi_heap_t* heap) {
|
||||
mi_assert(heap != NULL);
|
||||
mi_assert(mi_heap_is_initialized(heap));
|
||||
@ -321,6 +328,10 @@ void mi_heap_destroy(mi_heap_t* heap) {
|
||||
mi_heap_delete(heap);
|
||||
}
|
||||
else {
|
||||
// track all blocks as freed
|
||||
#if MI_TRACK_HEAP_DESTROY
|
||||
mi_heap_visit_blocks(heap, true, mi_heap_track_block_free, NULL);
|
||||
#endif
|
||||
// free all pages
|
||||
_mi_heap_destroy_pages(heap);
|
||||
mi_heap_free(heap);
|
||||
|
Loading…
x
Reference in New Issue
Block a user