summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2025-08-29 12:47:54 +0000
committerWilco Dijkstra <wilco.dijkstra@arm.com>2025-11-20 12:28:46 +0000
commit7f670284d8b691856c2d82a260ed22b296842755 (patch)
tree180c7e438a6f8b0e09e86c70802d54f1c66fe07d
parent92186652d8653993ca51e97b895baf7edc745794 (diff)
malloc: Use _int_free_chunk in tcache_thread_shutdown
Directly call _int_free_chunk during tcache shutdown to avoid recursion. Calling __libc_free on a block from tcache gets flagged as a double free, and tcache_double_free_verify checks every tcache chunk (quadratic overhead). Reviewed-by: Arjun Shankar <arjun@redhat.com>
-rw-r--r--malloc/malloc.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 975a005413..bd92d5c396 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3377,6 +3377,7 @@ static void
tcache_thread_shutdown (void)
{
int i;
+ mchunkptr p;
tcache_perthread_struct *tcache_tmp = tcache;
int need_free = tcache_enabled ();
@@ -3396,11 +3397,14 @@ tcache_thread_shutdown (void)
malloc_printerr ("tcache_thread_shutdown(): "
"unaligned tcache chunk detected");
tcache_tmp->entries[i] = REVEAL_PTR (e->next);
- __libc_free (e);
+ e->key = 0;
+ p = mem2chunk (e);
+ _int_free_chunk (arena_for_chunk (p), p, chunksize (p), 0);
}
}
- __libc_free (tcache_tmp);
+ p = mem2chunk (tcache_tmp);
+ _int_free_chunk (arena_for_chunk (p), p, chunksize (p), 0);
}
/* Initialize tcache. In the rare case there isn't any memory available,