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: nodejs#23117
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
danbev committed Oct 1, 2018
1 parent 1be804d commit 7ac109d
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 7ac109d

Please sign in to comment.