LibC: Don't leak memory for realloc(p, 0)

Previously we'd leak memory when the user called realloc(p, 0). Instead
this call should behave as if the user had called free(p).
This commit is contained in:
Gunnar Beutner 2021-05-29 14:46:10 +02:00 committed by Andreas Kling
parent 3ece67d62d
commit ea33e9647b
Notes: sideshowbarker 2024-07-18 17:12:13 +09:00

View file

@ -437,8 +437,10 @@ void* realloc(void* ptr, size_t size)
{
if (!ptr)
return malloc(size);
if (!size)
if (!size) {
free(ptr);
return nullptr;
}
Threading::Locker locker(malloc_lock());
auto existing_allocation_size = malloc_size(ptr);