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:
parent
7cc6c35eee
commit
f158b0b311
1 changed files with 4 additions and 0 deletions
|
@ -139,6 +139,10 @@ void * malloc(size_t sz) {
|
||||||
void * realloc(void * ptr, size_t sz) {
|
void * realloc(void * ptr, size_t sz) {
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
return malloc(sz);
|
return malloc(sz);
|
||||||
|
if (sz == 0) {
|
||||||
|
free(ptr);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
size_t old_sz = malloc_size(ptr);
|
size_t old_sz = malloc_size(ptr);
|
||||||
g_global_memory.dec(old_sz);
|
g_global_memory.dec(old_sz);
|
||||||
g_thread_memory.dec(old_sz);
|
g_thread_memory.dec(old_sz);
|
||||||
|
|
Loading…
Reference in a new issue