malloc_debug: reset TrackData mutex after fork
Add a pthread_atfork handler to malloc_debug to lock the TrackData mutex
during fork and reset it in the child. Ensures that the TrackData is
consistent when forking from a multi-threaded process, and that the
mutex is in a defined state in the child.
Change-Id: I0dfed30045a28551217ceac227d33b2e18894932
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/malloc_debug/DebugData.cpp
index bf2a0f5..cf16c29 100644
--- a/libc/malloc_debug/DebugData.cpp
+++ b/libc/malloc_debug/DebugData.cpp
@@ -82,3 +82,21 @@
}
return true;
}
+
+void DebugData::PrepareFork() {
+ if (track != nullptr) {
+ track->PrepareFork();
+ }
+}
+
+void DebugData::PostForkParent() {
+ if (track != nullptr) {
+ track->PostForkParent();
+ }
+}
+
+void DebugData::PostForkChild() {
+ if (track != nullptr) {
+ track->PostForkChild();
+ }
+}