From cc262a79199167ff4300fa3c02a51e8ae92a6004 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 27 Sep 2018 08:36:01 +0200 Subject: [PATCH] src: use unique_ptr for obj in SetWeak lambda --- src/base_object-inl.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index d067a807cb8e14..8c8fa1699c3069 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -95,13 +95,12 @@ void BaseObject::MakeWeak() { persistent_handle_.SetWeak( this, [](const v8::WeakCallbackInfo& data) { - BaseObject* obj = data.GetParameter(); + std::unique_ptr obj(data.GetParameter()); // Clear the persistent handle so that ~BaseObject() doesn't attempt // to mess with internal fields, since the JS object may have // transitioned into an invalid state. // Refs: https://github.com/nodejs/node/issues/18897 obj->persistent_handle_.Reset(); - delete obj; }, v8::WeakCallbackType::kParameter); }