Index: test/cctest/test-heap-profiler.cc |
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc |
index b96e1615669ef1574aec21ce34d244d23aabc538..552434ed8b5faeb2df65963dbcf24c1caee7438d 100644 |
--- a/test/cctest/test-heap-profiler.cc |
+++ b/test/cctest/test-heap-profiler.cc |
@@ -2021,6 +2021,7 @@ bool HasWeakGlobalHandle() { |
static void PersistentHandleCallback( |
const v8::WeakCallbackInfo<v8::Persistent<v8::Object> >& data) { |
data.GetParameter()->Reset(); |
+ delete data.GetParameter(); |
} |
@@ -2030,12 +2031,16 @@ TEST(WeakGlobalHandle) { |
CHECK(!HasWeakGlobalHandle()); |
- v8::Persistent<v8::Object> handle(env->GetIsolate(), |
- v8::Object::New(env->GetIsolate())); |
- handle.SetWeak(&handle, PersistentHandleCallback, |
- v8::WeakCallbackType::kParameter); |
+ // We cannot stack allocate the handle because the weak callback |
+ // can be invoked in the message loop after returning from this function. |
+ v8::Persistent<v8::Object>* handle = new v8::Persistent<v8::Object>(); |
+ |
+ handle->Reset(env->GetIsolate(), v8::Object::New(env->GetIsolate())); |
+ handle->SetWeak(handle, PersistentHandleCallback, |
+ v8::WeakCallbackType::kParameter); |
CHECK(HasWeakGlobalHandle()); |
+ CcTest::CollectAllGarbage(); |
} |