summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-29 14:46:10 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-29 19:40:23 +0200
commitea33e9647bec2d549b6a1a60fa9f4caf315aca92 (patch)
tree98792b01ca203b32cb2779178a0c2a49b4202ddf /Userland
parent3ece67d62d75b0407e3430b3c3d20011c08b62ef (diff)
downloadserenity-ea33e9647bec2d549b6a1a60fa9f4caf315aca92.zip
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).
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibC/malloc.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/malloc.cpp b/Userland/Libraries/LibC/malloc.cpp
index 7e57612db5..3331537293 100644
--- a/Userland/Libraries/LibC/malloc.cpp
+++ b/Userland/Libraries/LibC/malloc.cpp
@@ -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);