diff options
author | Florian Mayer <fmayer@google.com> | 2021-06-04 15:41:54 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-04 15:41:54 +0000 |
commit | 054a61c27eb2b0abe0fece989de481599440a9b1 (patch) | |
tree | 790d939aa65ad043194b9604e8fe13b68d862955 | |
parent | a3b1926d75c2e46083429ae1e952035480dc3221 (diff) | |
parent | b887dc0b5c5ac8ffa993a1ac6899ae92b6dbe8cb (diff) | |
download | bionic-054a61c27eb2b0abe0fece989de481599440a9b1.tar.gz |
Fix dangling pointer in heapprofd API. am: b887dc0b5c
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/14830782
Change-Id: I21dbe33547b63b10f3efab18a7ba2c880334c4ce
-rw-r--r-- | libc/bionic/malloc_heapprofd.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp index 198bcbab7..741b45e98 100644 --- a/libc/bionic/malloc_heapprofd.cpp +++ b/libc/bionic/malloc_heapprofd.cpp @@ -325,12 +325,12 @@ void HeapprofdRememberHookConflict() { static void CommonInstallHooks(libc_globals* globals) { void* impl_handle = atomic_load(&gHeapprofdHandle); - bool reusing_handle = impl_handle != nullptr; - if (!reusing_handle) { + if (impl_handle == nullptr) { impl_handle = LoadSharedLibrary(kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table); if (impl_handle == nullptr) { return; } + atomic_store(&gHeapprofdHandle, impl_handle); } else if (!InitSharedLibrary(impl_handle, kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table)) { return; } @@ -341,11 +341,7 @@ static void CommonInstallHooks(libc_globals* globals) { // MaybeModifyGlobals locks at this point. atomic_store(&gPreviousDefaultDispatchTable, GetDefaultDispatchTable()); - if (FinishInstallHooks(globals, nullptr, kHeapprofdPrefix)) { - atomic_store(&gHeapprofdHandle, impl_handle); - } else if (!reusing_handle) { - dlclose(impl_handle); - } + FinishInstallHooks(globals, nullptr, kHeapprofdPrefix); } void HeapprofdInstallHooksAtInit(libc_globals* globals) { |