1From 252e1127421c3c50c56d5c34a1a1b9251592b87c Mon Sep 17 00:00:00 2001
2From: JeffyChen <jeffy.chen@rock-chips.com>
3Date: Fri, 2 Jul 2021 17:39:24 +0200
4Subject: [PATCH 02/20] malloc: Initiate tcache shutdown even without
5 allocations [BZ #28028]
6
7After commit 1e26d35193efbb29239c710a4c46a64708643320 ("malloc: Fix
8tcache leak after thread destruction [BZ #22111]"),
9tcache_shutting_down is still not early enough.  When we detach a
10thread with no tcache allocated, tcache_shutting_down would still be
11false.
12
13Reviewed-by: DJ Delorie <dj@redhat.com>
14(cherry picked from commit dfec225ee1972488bb48a8b67a2c4a13010c334a)
15Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
16---
17 malloc/malloc.c | 3 ++-
18 1 file changed, 2 insertions(+), 1 deletion(-)
19
20diff --git a/malloc/malloc.c b/malloc/malloc.c
21index 27cf6137..c2ed8b6b 100644
22--- a/malloc/malloc.c
23+++ b/malloc/malloc.c
24@@ -2943,12 +2943,13 @@ tcache_thread_shutdown (void)
25   int i;
26   tcache_perthread_struct *tcache_tmp = tcache;
27
28+  tcache_shutting_down = true;
29+
30   if (!tcache)
31     return;
32
33   /* Disable the tcache and prevent it from being reinitialized.  */
34   tcache = NULL;
35-  tcache_shutting_down = true;
36
37   /* Free all of the entries and the tcache itself back to the arena
38      heap for coalescing.  */
39--
402.20.1
41
42