+2017-11-23 Florian Weimer <fweimer@redhat.com>
+
+ * malloc/malloc.c (tcache_thread_shutdown): Rename from
+ tcache_thread_freeres. Define for USE_TCACHE and !USE_TCACHE
+ alike. Remove freeres marker.
+ * malloc/arena.c (arena_thread_freeres): Call
+ tcache_thread_shutdown.
+
2017-11-23 Florian Weimer <fweimer@redhat.com>
[BZ #22459]
static void __attribute__ ((section ("__libc_thread_freeres_fn")))
arena_thread_freeres (void)
{
+ /* Shut down the thread cache first. This could deallocate data for
+ the thread arena, so do this before we put the arena on the free
+ list. */
+ tcache_thread_shutdown ();
+
mstate a = thread_arena;
thread_arena = NULL;
= memalign_hook_ini;
void weak_variable (*__after_morecore_hook) (void) = NULL;
+/* This function is called from the arena shutdown hook, to free the
+ thread cache (if it exists). */
+static void tcache_thread_shutdown (void);
/* ------------------ Testing support ----------------------------------*/
return (void *) e;
}
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-tcache_thread_freeres (void)
+static void
+tcache_thread_shutdown (void)
{
int i;
tcache_perthread_struct *tcache_tmp = tcache;
__libc_free (tcache_tmp);
}
-text_set_element (__libc_thread_subfreeres, tcache_thread_freeres);
static void
tcache_init(void)
}
-#define MAYBE_INIT_TCACHE() \
+# define MAYBE_INIT_TCACHE() \
if (__glibc_unlikely (tcache == NULL)) \
tcache_init();
-#else
-#define MAYBE_INIT_TCACHE()
-#endif
+#else /* !USE_TCACHE */
+# define MAYBE_INIT_TCACHE()
+
+static void
+tcache_thread_shutdown (void)
+{
+ /* Nothing to do if there is no thread cache. */
+}
+
+#endif /* !USE_TCACHE */
void *
__libc_malloc (size_t bytes)