From 166a9b85d9339c92c2efe9d8696360d0739bb217 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 | 3 +-- src/node_crypto.cc | 2 ++ src/req-wrap-inl.h | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 7f2a18e1d5f463..6625f4dd40fd42 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 { ~QueryWrap() override { CHECK_EQ(false, persistent().IsEmpty()); + ClearWrap(object()); persistent().Reset(); } diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 43c5490eefa888..3fc33cbd5bb58f 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -90,13 +90,12 @@ void HandleWrap::OnClose(uv_handle_t* handle) { HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local object = wrap->object(); if (wrap->flags_ & kCloseCallback) { wrap->MakeCallback(env->onclose_string(), 0, nullptr); } - 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 e047b30443df4f..4ae92946c8febb 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4761,6 +4761,7 @@ class PBKDF2Request : public AsyncWrap { ~PBKDF2Request() override { release(); + ClearWrap(object()); persistent().Reset(); } @@ -5026,6 +5027,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(); }