[PATCH] realloc: Fix mmap non-mremap reallocation case

Samuel Thibault samuel.thibault@ens-lyon.org
Mon Sep 28 18:57:47 GMT 2026


This case was missing copying SIZE_SZ bytes from the old allocation.

Fixes commit 614cfd0f8a2820aed54f9745077c7da0e6643bac
("malloc: Change mmap chunk layout"), which went into glibc 2.43.
---
 malloc/malloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 011ecd6870..a001875f25 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3132,7 +3132,7 @@ __libc_realloc (void *oldmem, size_t bytes)
       if (newmem == NULL)
         return NULL;              /* propagate failure */
 
-      memcpy (newmem, oldmem, oldsize - CHUNK_HDR_SZ);
+      memcpy (newmem, oldmem, usable);
       munmap_chunk (oldp);
       return newmem;
     }
-- 
2.53.0



More information about the Libc-alpha mailing list