From 4da3e1e461869414f80fc93b6122fe0f28791895 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Fri, 29 Apr 2016 12:26:35 -0600 Subject: [PATCH] src: always clear wrap before persistent Reset() In case the handle is stored and accessed after the associated C++ class was destructed, set the internal pointer to nullptr so any getters/setters can return accordingly without aborting the application. PR-URL: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/cares_wrap.cc | 2 ++ src/handle_wrap.cc | 2 +- src/node_crypto.cc | 2 ++ src/req-wrap-inl.h | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 6bd73ae3baf374..91d139ac9cd236 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -9,6 +9,7 @@ #include "req-wrap-inl.h" #include "tree.h" #include "util.h" +#include "util-inl.h" #include "uv.h" #include @@ -258,6 +259,7 @@ class QueryWrap : public AsyncWrap { virtual ~QueryWrap() override { CHECK_EQ(false, persistent().IsEmpty()); + ClearWrap(object()); persistent().Reset(); } diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index b3ef152a2ec1b0..c5792338af2fec 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -98,7 +98,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) { if (have_close_callback) wrap->MakeCallback(env->onclose_string(), 0, nullptr); - wrap->object()->SetAlignedPointerInInternalField(0, nullptr); + ClearWrap(wrap->object()); wrap->persistent().Reset(); delete wrap; } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 71799d0bfa3ef3..71e1272e9dc361 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5023,6 +5023,7 @@ class PBKDF2Request : public AsyncWrap { ~PBKDF2Request() override { release(); + ClearWrap(object()); persistent().Reset(); } @@ -5288,6 +5289,7 @@ class RandomBytesRequest : public AsyncWrap { } ~RandomBytesRequest() override { + ClearWrap(object()); persistent().Reset(); } diff --git a/src/req-wrap-inl.h b/src/req-wrap-inl.h index 63229260ec7517..653babd2a70c65 100644 --- a/src/req-wrap-inl.h +++ b/src/req-wrap-inl.h @@ -28,6 +28,7 @@ template ReqWrap::~ReqWrap() { CHECK_EQ(req_.data, this); // Assert that someone has called Dispatched(). CHECK_EQ(false, persistent().IsEmpty()); + ClearWrap(object()); persistent().Reset(); }