diff options
author | Christopher Ferris <cferris@google.com> | 2015-07-13 20:15:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-13 20:15:30 +0000 |
commit | 43d35c356e2fbe0b022cef52445e93053c4ddbfd (patch) | |
tree | 680d4c3dc2307bc735c73220ae7197c64b6db336 /libc | |
parent | 64c825441637b379be56a04622089e8e9b4b0da4 (diff) | |
parent | 9fee99b06013787054a312449b94115038e2ad7c (diff) | |
download | bionic-43d35c356e2fbe0b022cef52445e93053c4ddbfd.zip bionic-43d35c356e2fbe0b022cef52445e93053c4ddbfd.tar.gz bionic-43d35c356e2fbe0b022cef52445e93053c4ddbfd.tar.bz2 |
Merge "Do not hold hash table lock while backtracing." into mnc-dev
Diffstat (limited to 'libc')
-rw-r--r-- | libc/bionic/malloc_debug_leak.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp index 64f2112..6a46667 100644 --- a/libc/bionic/malloc_debug_leak.cpp +++ b/libc/bionic/malloc_debug_leak.cpp @@ -133,8 +133,9 @@ static HashEntry* record_backtrace(uintptr_t* backtrace, size_t numEntries, size size |= SIZE_FLAG_ZYGOTE_CHILD; } + // Keep the lock held for as little time as possible to prevent deadlocks. + ScopedPthreadMutexLocker locker(&g_hash_table->lock); HashEntry* entry = find_entry(g_hash_table, slot, backtrace, numEntries, size); - if (entry != NULL) { entry->allocations++; } else { @@ -302,8 +303,6 @@ extern "C" void* leak_malloc(size_t bytes) { void* base = g_malloc_dispatch->malloc(size); if (base != NULL) { - ScopedPthreadMutexLocker locker(&g_hash_table->lock); - uintptr_t backtrace[BACKTRACE_SIZE]; size_t numEntries = GET_BACKTRACE(backtrace, BACKTRACE_SIZE); @@ -328,8 +327,6 @@ extern "C" void leak_free(void* mem) { return; } - ScopedPthreadMutexLocker locker(&g_hash_table->lock); - // check the guard to make sure it is valid AllocationEntry* header = to_header(mem); @@ -342,6 +339,7 @@ extern "C" void leak_free(void* mem) { } } + ScopedPthreadMutexLocker locker(&g_hash_table->lock); if (header->guard == GUARD || is_valid_entry(header->entry)) { // decrement the allocations HashEntry* entry = header->entry; |