From 3efabc342f7eea8e16aa157dd4ac51a2023df079 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sun, 12 Feb 2023 23:45:13 +0800 Subject: [PATCH] fix(memory): fix segfault error caused by freeing nullptr with Free() --- Redcraft.Utility/Source/Private/Memory/Memory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Redcraft.Utility/Source/Private/Memory/Memory.cpp b/Redcraft.Utility/Source/Private/Memory/Memory.cpp index f87835d..ec9ff63 100644 --- a/Redcraft.Utility/Source/Private/Memory/Memory.cpp +++ b/Redcraft.Utility/Source/Private/Memory/Memory.cpp @@ -127,6 +127,8 @@ void* Realloc(void* Ptr, size_t Count, size_t Alignment) void Free(void* Ptr) { + if (Ptr == nullptr) return; + # if PLATFORM_WINDOWS { _aligned_free(Ptr); @@ -137,7 +139,7 @@ void Free(void* Ptr) } # endif - check_code({ if (Ptr != nullptr) MemoryLeakChecker.ReleaseMemoryAllocationCount(); }); + check_code({ MemoryLeakChecker.ReleaseMemoryAllocationCount(); }); } size_t QuantizeSize(size_t Count, size_t Alignment)