From f158b0b3112c80b668cfbb7cf61e72c7473f2aaa Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 11 Nov 2013 13:42:22 -0800 Subject: [PATCH] fix(util/memory): make sure realloc behaves like free when sz == 0 Signed-off-by: Leonardo de Moura --- src/util/memory.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/memory.cpp b/src/util/memory.cpp index b8e9ce884..51cc802f9 100644 --- a/src/util/memory.cpp +++ b/src/util/memory.cpp @@ -139,6 +139,10 @@ void * malloc(size_t sz) { void * realloc(void * ptr, size_t sz) { if (ptr == nullptr) return malloc(sz); + if (sz == 0) { + free(ptr); + return nullptr; + } size_t old_sz = malloc_size(ptr); g_global_memory.dec(old_sz); g_thread_memory.dec(old_sz);