diff --git a/malloc.c b/malloc.c index 4a03961..e135f01 100644 --- a/malloc.c +++ b/malloc.c @@ -512,10 +512,6 @@ static inline void deallocate_small(void *p, const size_t *expected_size) { } if (!is_zero_size) { - if (ZERO_ON_FREE) { - memset(p, 0, size - canary_size); - } - if (canary_size) { u64 canary_value; memcpy(&canary_value, (char *)p + size - canary_size, canary_size); @@ -523,6 +519,10 @@ static inline void deallocate_small(void *p, const size_t *expected_size) { fatal_error("canary corrupted"); } } + + if (ZERO_ON_FREE) { + memset(p, 0, size - canary_size); + } } if (!has_free_slots(slots, metadata)) {