Skip to content

Commit 668bc11

Browse files
addaleaxmmarchini
authored andcommittedMar 23, 2020
src: delete BaseObjectWeakPtr data when pointee is gone
Fix the condition for deleting the underlying data pointed to by a `BaseObjectWeakPtr`, which erroneously skipped that deletion when `ptr->get()` was `nullptr`. This fixes a memory leak reported by some of the tests. Refs: nodejs#30374 (comment) PR-URL: nodejs#32393 Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f2b0fb2 commit 668bc11

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎src/base_object-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
234234

235235
template <typename T, bool kIsWeak>
236236
BaseObjectPtrImpl<T, kIsWeak>::~BaseObjectPtrImpl() {
237-
if (get() == nullptr) return;
238237
if (kIsWeak) {
239-
if (--pointer_data()->weak_ptr_count == 0 &&
238+
if (pointer_data() != nullptr &&
239+
--pointer_data()->weak_ptr_count == 0 &&
240240
pointer_data()->self == nullptr) {
241241
delete pointer_data();
242242
}
243-
} else {
243+
} else if (get() != nullptr) {
244244
get()->decrease_refcount();
245245
}
246246
}

0 commit comments

Comments
 (0)
Please sign in to comment.