6c0556
commit dfec225ee1972488bb48a8b67a2c4a13010c334a
6c0556
Author: JeffyChen <jeffy.chen@rock-chips.com>
6c0556
Date:   Fri Jul 2 17:39:24 2021 +0200
6c0556
6c0556
    malloc: Initiate tcache shutdown even without allocations [BZ #28028]
6c0556
    
6c0556
    After commit 1e26d35193efbb29239c710a4c46a64708643320 ("malloc: Fix
6c0556
    tcache leak after thread destruction [BZ #22111]"),
6c0556
    tcache_shutting_down is still not early enough.  When we detach a
6c0556
    thread with no tcache allocated, tcache_shutting_down would still be
6c0556
    false.
6c0556
    
6c0556
    Reviewed-by: DJ Delorie <dj@redhat.com>
6c0556
6c0556
diff --git a/malloc/malloc.c b/malloc/malloc.c
6c0556
index 00a37f218c0ab3b2..61f7bdc76064c340 100644
6c0556
--- a/malloc/malloc.c
6c0556
+++ b/malloc/malloc.c
6c0556
@@ -2960,12 +2960,13 @@ tcache_thread_shutdown (void)
6c0556
   int i;
6c0556
   tcache_perthread_struct *tcache_tmp = tcache;
6c0556
 
6c0556
+  tcache_shutting_down = true;
6c0556
+
6c0556
   if (!tcache)
6c0556
     return;
6c0556
 
6c0556
   /* Disable the tcache and prevent it from being reinitialized.  */
6c0556
   tcache = NULL;
6c0556
-  tcache_shutting_down = true;
6c0556
 
6c0556
   /* Free all of the entries and the tcache itself back to the arena
6c0556
      heap for coalescing.  */