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