Skip to content

Commit 76b0873

Browse files
committed
fix asan tracking by explicitly setting memory to undefined before a free
1 parent 3f69119 commit 76b0873

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/arena.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ void _mi_arena_free(void* p, size_t size, size_t committed_size, mi_memid_t memi
627627
if (size==0) return;
628628
const bool all_committed = (committed_size == size);
629629

630+
// need to set all memory to undefined as some parts may still be marked as no_access (like padding etc.)
631+
mi_track_mem_undefined(p,size);
632+
630633
if (mi_memkind_is_os(memid.memkind)) {
631634
// was a direct OS allocation, pass through
632635
if (!all_committed && committed_size > 0) {
@@ -656,9 +659,6 @@ void _mi_arena_free(void* p, size_t size, size_t committed_size, mi_memid_t memi
656659
return;
657660
}
658661

659-
// need to set all memory to undefined as some parts may still be marked as no_access (like padding etc.)
660-
mi_track_mem_undefined(p,size);
661-
662662
// potentially decommit
663663
if (arena->memid.is_pinned || arena->blocks_committed == NULL) {
664664
mi_assert_internal(all_committed);

src/page.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static mi_page_t* mi_find_page(mi_heap_t* heap, size_t size, size_t huge_alignme
857857
// huge allocation?
858858
const size_t req_size = size - MI_PADDING_SIZE; // correct for padding_size in case of an overflow on `size`
859859
if mi_unlikely(req_size > (MI_LARGE_OBJ_SIZE_MAX - MI_PADDING_SIZE) || huge_alignment > 0) {
860-
if mi_unlikely(req_size > MI_MAX_ALLOC_SIZE) {
860+
if mi_unlikely(req_size > MI_MAX_ALLOC_SIZE) {
861861
_mi_error_message(EOVERFLOW, "allocation request is too large (%zu bytes)\n", req_size);
862862
return NULL;
863863
}

test/test-stress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ static void free_items(void* p) {
133133
custom_free(p);
134134
}
135135

136-
#ifdef HEAP_WALK
136+
#ifdef HEAP_WALK
137137
static bool visit_blocks(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg) {
138-
(void)(heap); (void)(area);
138+
(void)(heap); (void)(area);
139139
size_t* total = (size_t*)arg;
140140
if (block != NULL) {
141141
*total += block_size;
@@ -260,7 +260,7 @@ static void test_leak(void) {
260260

261261
int main(int argc, char** argv) {
262262
#ifdef HEAP_WALK
263-
mi_option_enable(mi_option_visit_abandoned);
263+
mi_option_enable(mi_option_visit_abandoned);
264264
#endif
265265
#ifndef NDEBUG
266266
mi_option_set(mi_option_arena_reserve, 32 * 1024 /* in kib = 32MiB */);

0 commit comments

Comments
 (0)