From 00915521a3eda96f82f393cecc41b5fc39501140 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 28 Oct 2018 21:07:35 -0400 Subject: [PATCH] check canary before zeroing as an optimization --- malloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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)) {