From 97a11475371c13cee565803dcc24ef137b932484 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 6 Sep 2021 19:34:44 +0100 Subject: [PATCH] Correct fix to `heap_allocator_proc` in compiler --- src/common_memory.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/common_memory.cpp b/src/common_memory.cpp index bd3d2d5de..418470c19 100644 --- a/src/common_memory.cpp +++ b/src/common_memory.cpp @@ -351,20 +351,19 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { } break; case gbAllocation_Free: - if (!old_memory) { + if (old_memory != nullptr) { free(old_memory); } break; case gbAllocation_Resize: - if (!old_memory) { - break; - } if (size == 0) { - free(old_memory); + if (old_memory != nullptr) { + free(old_memory); + } break; } - if (!old_memory) { + if (old_memory == nullptr) { ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1)); gb_zero_size(ptr, size); break; @@ -386,20 +385,17 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { break; case gbAllocation_Free: - if (!old_memory) { + if (old_memory != nullptr) { free(old_memory); } break; case gbAllocation_Resize: - if (!old_memory) { - break; - } if (size == 0) { free(old_memory); break; } - if (!old_memory) { + if (old_memory == nullptr) { posix_memalign(&ptr, alignment, size); gb_zero_size(ptr, size); break;