Skip to content

Commit fbd5be6

Browse files
addaleaxMylesBorins
authored andcommitted
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: #30374 (comment) Backport-PR-URL: #32301 PR-URL: #32393 Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 56a4509 commit fbd5be6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/base_object-inl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
230230

231231
template <typename T, bool kIsWeak>
232232
BaseObjectPtrImpl<T, kIsWeak>::~BaseObjectPtrImpl() {
233-
if (get() == nullptr) return;
234233
if (kIsWeak) {
235-
if (--pointer_data()->weak_ptr_count == 0 &&
234+
if (pointer_data() != nullptr &&
235+
--pointer_data()->weak_ptr_count == 0 &&
236236
pointer_data()->self == nullptr) {
237237
delete pointer_data();
238238
}
239-
} else {
239+
} else if (get() != nullptr) {
240240
get()->decrease_refcount();
241241
}
242242
}

0 commit comments

Comments
 (0)