Skip to content

Commit

Permalink
src: use unique_ptr for obj in SetWeak lambda
Browse files Browse the repository at this point in the history
PR-URL: #23117
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and targos committed Oct 3, 2018
1 parent 23525b0 commit ce7fad5
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ void BaseObject::MakeWeak() {
persistent_handle_.SetWeak(
this,
[](const v8::WeakCallbackInfo<BaseObject>& data) {
BaseObject* obj = data.GetParameter();
std::unique_ptr<BaseObject> 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);
}

Expand Down

0 comments on commit ce7fad5

Please sign in to comment.