Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ static void mi_heap_free(mi_heap_t* heap, bool do_free_mem) {

// and free the used memory
if (do_free_mem) {
_mi_meta_free(heap, sizeof(*heap), heap->memid);
const size_t actual_size = (heap->memid.memkind == MI_MEM_ARENA
? (size_t)heap->memid.mem.arena.slice_count * MI_ARENA_SLICE_SIZE
: sizeof(*heap));
_mi_meta_free(heap, actual_size, heap->memid);
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/test-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ we therefore test the API over various inputs. Please add more tests :-)
// ---------------------------------------------------------------------------
bool test_heap1(void);
bool test_heap2(void);
bool test_heap_arena_destroy(void);
bool test_heap_arena_delete(void);
bool test_stl_allocator1(void);
bool test_stl_allocator2(void);

Expand Down Expand Up @@ -339,6 +341,8 @@ int main(void) {
// ---------------------------------------------------
CHECK("heap_destroy", test_heap1());
CHECK("heap_delete", test_heap2());
CHECK("heap_arena_destroy", test_heap_arena_destroy());
CHECK("heap_arena_delete", test_heap_arena_delete());

//mi_stats_print(NULL);

Expand Down Expand Up @@ -391,6 +395,32 @@ bool test_heap2(void) {
return true;
}

bool test_heap_arena_destroy(void) {
mi_arena_id_t arena_id = NULL;
if (mi_reserve_os_memory_ex(32 * 1024 * 1024, true, false, true, &arena_id) != 0) {
return false;
}
mi_heap_t* heap = mi_heap_new_ex(0, true, arena_id);
if (heap == NULL) {
return false;
}
mi_heap_destroy(heap);
return true;
}

bool test_heap_arena_delete(void) {
mi_arena_id_t arena_id = NULL;
if (mi_reserve_os_memory_ex(32 * 1024 * 1024, true, false, true, &arena_id) != 0) {
return false;
}
mi_heap_t* heap = mi_heap_new_ex(0, true, arena_id);
if (heap == NULL) {
return false;
}
mi_heap_delete(heap);
return true;
}

bool test_stl_allocator1(void) {
#ifdef __cplusplus
std::vector<int, mi_stl_allocator<int> > vec;
Expand Down