Skip to content

Commit

Permalink
src: fix BaseObject Detach for GC’ed objects
Browse files Browse the repository at this point in the history
This fixes a crash in test/sequential/test-performance-eventloopdelay.js.
This should be squashed into

> src: introduce custom smart pointers for `BaseObject`s

PR-URL: nodejs#149
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and juanarbol committed Dec 17, 2019
1 parent 03481be commit f44051e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ void BaseObject::decrease_refcount() {
if (new_refcount == 0) {
if (metadata->is_detached) {
delete this;
} else if (metadata->wants_weak_jsobj) {
} else if (metadata->wants_weak_jsobj && !persistent_handle_.IsEmpty()) {
MakeWeak();
}
}
}

void BaseObject::increase_refcount() {
unsigned int prev_refcount = pointer_data()->strong_ptr_count++;
if (prev_refcount == 0)
if (prev_refcount == 0 && !persistent_handle_.IsEmpty())
persistent_handle_.ClearWeak();
}

Expand Down

0 comments on commit f44051e

Please sign in to comment.