fix(util/memory): make sure realloc behaves like free when sz == 0

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-11-11 13:42:22 -08:00
parent 7cc6c35eee
commit f158b0b311

View file

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