Skip to content

Commit

Permalink
src: delete BaseObjectWeakPtr data when pointee is gone
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
addaleax authored and MylesBorins committed Apr 1, 2020
1 parent 56a4509 commit fbd5be6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,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();
}
}
Expand Down

0 comments on commit fbd5be6

Please sign in to comment.