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);