[PATCH] malloc: free original oldmem with tcache in realloc
Rocket Ma
marocketbd@gmail.com
Tue Mar 31 08:26:31 GMT 2026
This patch reintroduced tcache support in realloc. In commit cd335350,
all chunks released in realloc is directly put into bins for
performance. For remainder ones, it's OK, since user never allocate
these manually; though if the chunk grows instead of shrinks, the chunk
to free is allocated by user some time ago. These chunks requested by
user should be put in tcache if available.
Signed-off-by: Rocket Ma <marocketbd@gmail.com>
---
malloc/malloc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 6455a1b0e0..503e981271 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3471,8 +3471,7 @@ __libc_realloc (void *oldmem, size_t bytes)
{
size_t sz = memsize (oldp);
memcpy (newp, oldmem, sz);
- (void) tag_region (chunk2mem (oldp), sz);
- _int_free_chunk (ar_ptr, oldp, chunksize (oldp), 0);
+ __libc_free (oldmem);
}
}
@@ -4549,7 +4548,7 @@ _int_realloc (mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
(void) tag_region (oldmem, sz);
newmem = tag_new_usable (newmem);
memcpy (newmem, oldmem, sz);
- _int_free_chunk (av, oldp, chunksize (oldp), 1);
+ __libc_free (oldmem);
check_inuse_chunk (av, newp);
return newmem;
}
--
2.53.0
More information about the Libc-alpha
mailing list