From d7c25ee0027f8eb2d06675806d4839b135959191 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 6 Mar 2018 11:53:15 +0100 Subject: [PATCH 1/2] src: use smart pointer in AsyncWrap::WeakCallback --- src/async_wrap.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 08bb73f7468707..5b184018f53da4 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -415,14 +415,13 @@ void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo& info) { HandleScope scope(info.GetIsolate()); Environment* env = Environment::GetCurrent(info.GetIsolate()); - DestroyParam* p = info.GetParameter(); + std::unique_ptr p{info.GetParameter()}; Local prop_bag = PersistentToLocal(info.GetIsolate(), p->propBag); Local val = prop_bag->Get(env->destroyed_string()); if (val->IsFalse()) { AsyncWrap::EmitDestroy(env, p->asyncId); } - delete p; } From 36f0e370d561dc7d7e15c3d130ccc84b140a5fdb Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 6 Mar 2018 13:30:31 +0100 Subject: [PATCH 2/2] squash: add comment about scope of unique_ptr --- src/async_wrap.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 5b184018f53da4..e2656e4eec3970 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -422,6 +422,7 @@ void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo& info) { if (val->IsFalse()) { AsyncWrap::EmitDestroy(env, p->asyncId); } + // unique_ptr goes out of scope here and pointer is deleted. }