summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc/realloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc/realloc.c')
-rw-r--r--libc/stdlib/malloc/realloc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index e8906422d..4372751d0 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -28,9 +28,10 @@ realloc (void *mem, size_t new_size)
char *base_mem = MALLOC_BASE (mem);
size_t size = MALLOC_SIZE (mem);
- /* Make sure that we're dealing in a multiple of the heap allocation
- unit (SIZE is already guaranteed to be so). */
- new_size = HEAP_ADJUST_SIZE (new_size);
+ /* Include extra space to record the size of the allocated block.
+ Also make sure that we're dealing in a multiple of the heap
+ allocation unit (SIZE is already guaranteed to be so).*/
+ new_size = HEAP_ADJUST_SIZE (new_size + MALLOC_HEADER_SIZE);
MALLOC_DEBUG ("realloc: 0x%lx, %d (base = 0x%lx, total_size = %d)\n",
(long)mem, new_size, (long)base_mem, size);