diff options
author | Colin Cross <ccross@android.com> | 2016-02-17 20:38:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-17 20:38:02 +0000 |
commit | 598cb89790ba93edbb392c567ecda32b39d64ff1 (patch) | |
tree | 28f8dc579b1462a232620d180ab5f32a88f687f4 /libc/malloc_debug/malloc_debug.cpp | |
parent | 2de48bc809bba48a7f209e209b3822bad010166f (diff) | |
parent | 7a28a3cf1f8df36e30724e8b4021cddde0596118 (diff) |
Merge "malloc_debug: reset TrackData mutex after fork"
Diffstat (limited to 'libc/malloc_debug/malloc_debug.cpp')
-rw-r--r-- | libc/malloc_debug/malloc_debug.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index 0c0907d00..dcc6048f7 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -85,6 +85,28 @@ void* debug_valloc(size_t size); __END_DECLS // ------------------------------------------------------------------------ +static void InitAtfork() { + static pthread_once_t atfork_init = PTHREAD_ONCE_INIT; + pthread_once(&atfork_init, [](){ + pthread_atfork( + [](){ + if (g_debug != nullptr) { + g_debug->PrepareFork(); + } + }, + [](){ + if (g_debug != nullptr) { + g_debug->PostForkParent(); + } + }, + [](){ + if (g_debug != nullptr) { + g_debug->PostForkChild(); + } + } + ); + }); +} static void LogTagError(const Header* header, const void* pointer, const char* name) { ScopedDisableDebugCalls disable; @@ -156,6 +178,9 @@ bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_ if (malloc_zygote_child == nullptr) { return false; } + + InitAtfork(); + g_malloc_zygote_child = malloc_zygote_child; g_dispatch = malloc_dispatch; |