summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc-simple/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc-simple/alloc.c')
-rw-r--r--libc/stdlib/malloc-simple/alloc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index f31105d4e..f278a9583 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -99,10 +99,12 @@ void *realloc(void *ptr, size_t size)
if (size > 0) {
newptr = malloc(size);
- if (newptr && ptr)
+ if (newptr && ptr) {
memcpy(newptr, ptr, size);
+ free(ptr);
+ }
}
- if (ptr)
+ else
free(ptr);
return newptr;
}