Fix dangling pointer in heapprofd API.
We would dlopen heapprofd_client.so, which has a static initializer [1] that passes a pointer to of its functions to heapprofd_client_api.so. If we dlclose heapprofd_client.so, this pointer is dangling. [1]: https://cs.android.com/android/platform/superproject/+/master:external/perfetto/src/profiling/memory/malloc_interceptor_bionic_hooks.cc?q=symbol:g_heap_id Bug: 189332777 Change-Id: Ia4a9d9dd7c89eceec86c6fac5f4b66de85d7604e
This commit is contained in:
parent
64be12fbc9
commit
85c7838bd9
1 changed files with 3 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue