Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-03-20 21:58:57 +0300
committerMatheus Marchini <mmarchini@netflix.com>2020-03-23 22:06:24 +0300
commit668bc11c1bbca429281ffdc78a9d4dda3d34af30 (patch)
treeba4155b62f038a9ac6a8bfb7daafe713ffb2ad20 /src/base_object-inl.h
parentf2b0fb270d23489524a66812642964b0bd3c21bc (diff)
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>
Diffstat (limited to 'src/base_object-inl.h')
-rw-r--r--src/base_object-inl.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/base_object-inl.h b/src/base_object-inl.h
index c9b4e1491fc..fc2611444c1 100644
--- a/src/base_object-inl.h
+++ b/src/base_object-inl.h
@@ -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();
}
}