From dba6d44376a3301acfb8fd7e7c5159b25736b09e Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 20 Mar 2019 21:09:46 -0700 Subject: [PATCH] libprocessgroup: Deliberately leak TaskProfiles and CgroupMap instances. This avoids a race between destruction on process exit and concurrent access from another thread. Bug: 129023204 Change-Id: Iecafa67a78e2cce53687156e7f91547b4a23ec13 --- libprocessgroup/cgroup_map.cpp | 6 ++++-- libprocessgroup/task_profiles.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index 995162186..b3b497f68 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -336,8 +336,10 @@ CgroupMap::~CgroupMap() { } CgroupMap& CgroupMap::GetInstance() { - static CgroupMap instance; - return instance; + // Deliberately leak this object to avoid a race between destruction on + // process exit and concurrent access from another thread. + static auto* instance = new CgroupMap; + return *instance; } bool CgroupMap::LoadRcFile() { diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index f1fbcdebe..9362c0387 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -284,8 +284,10 @@ bool TaskProfile::ExecuteForTask(int tid) const { } TaskProfiles& TaskProfiles::GetInstance() { - static TaskProfiles instance; - return instance; + // Deliberately leak this object to avoid a race between destruction on + // process exit and concurrent access from another thread. + static auto* instance = new TaskProfiles; + return *instance; } TaskProfiles::TaskProfiles() {