mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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: https://github.com/nodejs/node/pull/30374#issuecomment-601848973 PR-URL: https://github.com/nodejs/node/pull/32393 Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
2bcf535a05
commit
6f06cf0bf4
1 file changed
+3
-3
@@ -234,13 +234,13 @@ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
|
||||
|
||||
template <typename T, bool kIsWeak>
|
||||
BaseObjectPtrImpl<T, kIsWeak>::~BaseObjectPtrImpl() {
|
||||
if (get() == nullptr) return;
|
||||
if (kIsWeak) {
|
||||
if (--pointer_data()->weak_ptr_count == 0 &&
|
||||
if (pointer_data() != nullptr &&
|
||||
--pointer_data()->weak_ptr_count == 0 &&
|
||||
pointer_data()->self == nullptr) {
|
||||
delete pointer_data();
|
||||
}
|
||||
} else {
|
||||
} else if (get() != nullptr) {
|
||||
get()->decrease_refcount();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user