Skip to content

Commit 166a9b8

Browse files
trevnorrisMylesBorins
authored andcommitted
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: #6184 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent b3149ce commit 166a9b8

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

src/cares_wrap.cc

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "req-wrap-inl.h"
1010
#include "tree.h"
1111
#include "util.h"
12+
#include "util-inl.h"
1213
#include "uv.h"
1314

1415
#include <errno.h>
@@ -258,6 +259,7 @@ class QueryWrap : public AsyncWrap {
258259

259260
~QueryWrap() override {
260261
CHECK_EQ(false, persistent().IsEmpty());
262+
ClearWrap(object());
261263
persistent().Reset();
262264
}
263265

src/handle_wrap.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
9090

9191
HandleScope handle_scope(env->isolate());
9292
Context::Scope context_scope(env->context());
93-
Local<Object> object = wrap->object();
9493

9594
if (wrap->flags_ & kCloseCallback) {
9695
wrap->MakeCallback(env->onclose_string(), 0, nullptr);
9796
}
9897

99-
object->SetAlignedPointerInInternalField(0, nullptr);
98+
ClearWrap(wrap->object());
10099
wrap->persistent().Reset();
101100
delete wrap;
102101
}

src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4761,6 +4761,7 @@ class PBKDF2Request : public AsyncWrap {
47614761

47624762
~PBKDF2Request() override {
47634763
release();
4764+
ClearWrap(object());
47644765
persistent().Reset();
47654766
}
47664767

@@ -5026,6 +5027,7 @@ class RandomBytesRequest : public AsyncWrap {
50265027
}
50275028

50285029
~RandomBytesRequest() override {
5030+
ClearWrap(object());
50295031
persistent().Reset();
50305032
}
50315033

src/req-wrap-inl.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ template <typename T>
2828
ReqWrap<T>::~ReqWrap() {
2929
CHECK_EQ(req_.data, this); // Assert that someone has called Dispatched().
3030
CHECK_EQ(false, persistent().IsEmpty());
31+
ClearWrap(object());
3132
persistent().Reset();
3233
}
3334

0 commit comments

Comments
 (0)