Skip to content

Commit

Permalink
src: always clear wrap before persistent Reset()
Browse files Browse the repository at this point in the history
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 <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
trevnorris authored and rvagg committed Jun 2, 2016
1 parent 7e57757 commit 4da3e1e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "req-wrap-inl.h"
#include "tree.h"
#include "util.h"
#include "util-inl.h"
#include "uv.h"

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

virtual ~QueryWrap() override {
CHECK_EQ(false, persistent().IsEmpty());
ClearWrap(object());
persistent().Reset();
}

Expand Down
2 changes: 1 addition & 1 deletion src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5023,6 +5023,7 @@ class PBKDF2Request : public AsyncWrap {

~PBKDF2Request() override {
release();
ClearWrap(object());
persistent().Reset();
}

Expand Down Expand Up @@ -5288,6 +5289,7 @@ class RandomBytesRequest : public AsyncWrap {
}

~RandomBytesRequest() override {
ClearWrap(object());
persistent().Reset();
}

Expand Down
1 change: 1 addition & 0 deletions src/req-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template <typename T>
ReqWrap<T>::~ReqWrap() {
CHECK_EQ(req_.data, this); // Assert that someone has called Dispatched().
CHECK_EQ(false, persistent().IsEmpty());
ClearWrap(object());
persistent().Reset();
}

Expand Down

0 comments on commit 4da3e1e

Please sign in to comment.