Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: runtime/vm/malloc_hooks.cc

Issue 2701013002: Resolution for issue #28746: changed order in which locks/flags are grabbed in MallocHooks to preve… (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/malloc_hooks.cc
diff --git a/runtime/vm/malloc_hooks.cc b/runtime/vm/malloc_hooks.cc
index 9e5c6587c3065498c8a757de121770e315e1b03d..b1cfef046d7ae73c4573efd637faf0e2293b9078 100644
--- a/runtime/vm/malloc_hooks.cc
+++ b/runtime/vm/malloc_hooks.cc
@@ -173,8 +173,10 @@ class MallocHooksState : public AllStatic {
};
-// MallocHooks state / locks.
+// MallocHookScope state.
ThreadLocalKey MallocHookScope::in_malloc_hook_flag_ = kUnsetThreadLocalKey;
+
+// MallocHooks state / locks.
bool MallocHooksState::active_ = false;
intptr_t MallocHooksState::original_pid_ = MallocHooksState::kInvalidPid;
Mutex* MallocHooksState::malloc_hook_mutex_ = new Mutex();
@@ -270,11 +272,11 @@ void MallocHooksState::RecordAllocHook(const void* ptr, size_t size) {
return;
}
- // Set the malloc hook flag before grabbing the mutex to avoid calling hooks
- // again.
- MallocHookScope mhs;
MutexLocker ml(MallocHooksState::malloc_hook_mutex());
zra 2017/02/17 18:41:02 I think taking the log and checking Active() needs
bkonyi 2017/02/17 21:15:11 We can't take the lock before anything else, or el
if ((ptr != NULL) && MallocHooksState::Active()) {
+ // Set the malloc hook flag before to avoid calling hooks again if memory is
+ // allocated/freed below.
+ MallocHookScope mhs;
MallocHooksState::IncrementHeapAllocatedMemoryInBytes(size);
MallocHooksState::address_map()->Insert(ptr, size);
}
@@ -286,11 +288,11 @@ void MallocHooksState::RecordFreeHook(const void* ptr) {
return;
}
- // Set the malloc hook flag before grabbing the mutex to avoid calling hooks
- // again.
- MallocHookScope mhs;
MutexLocker ml(MallocHooksState::malloc_hook_mutex());
zra 2017/02/17 18:41:02 ditto
bkonyi 2017/02/17 21:15:11 See above.
if ((ptr != NULL) && MallocHooksState::Active()) {
+ // Set the malloc hook flag before to avoid calling hooks again if memory is
+ // allocated/freed below.
+ MallocHookScope mhs;
intptr_t size = 0;
if (MallocHooksState::address_map()->Lookup(ptr, &size)) {
MallocHooksState::DecrementHeapAllocatedMemoryInBytes(size);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698