diff options
author | Florian Mayer <fmayer@google.com> | 2021-03-05 17:36:54 +0000 |
---|---|---|
committer | Florian Mayer <fmayer@google.com> | 2021-03-05 17:36:54 +0000 |
commit | 1a3c8d43004ac31321841d5963aeea65eeab31fa (patch) | |
tree | 87bd249e4459b4766efcc63892e12d19e8a630f3 | |
parent | c34758e76b5aa6c3cd4510efffef169c43752438 (diff) | |
download | perfetto-1a3c8d43004ac31321841d5963aeea65eeab31fa.tar.gz |
Do not call heap callbacks in atfork.
This can lead to deadlocks if we fork at a point where we hold a lock
that is required for the disable callbacks. For instance, the Bionic
interceptor callback protects some state using a lock.
Change-Id: I37acefd2e26693ee1fe71d185fe09783f0416dea
Bug: 181031512
Bug: 176829629
-rw-r--r-- | src/profiling/memory/client_api.cc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/profiling/memory/client_api.cc b/src/profiling/memory/client_api.cc index cf9058987..bdede0d57 100644 --- a/src/profiling/memory/client_api.cc +++ b/src/profiling/memory/client_api.cc @@ -250,8 +250,12 @@ void AtForkChild() { g_client_lock.locked.store(false); g_client_lock.poisoned.store(false); - DisableAllHeaps(); - + // We must not call the disabled callbacks here, because they might require + // locks that are being held at the fork point. + for (uint32_t i = kMinHeapId; i < g_next_heap_id.load(); ++i) { + AHeapInfo& info = GetHeap(i); + info.enabled.store(false); + } // Leak the existing shared_ptr contents, including the profiling |Client| if // profiling was active at the time of the fork. // Note: this code assumes that the creation of the empty shared_ptr does not |