diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2018-02-21 17:24:18 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2018-02-21 17:24:18 +0300 |
commit | 992703f2b50f6b3483e9b930737d177b9e01256d (patch) | |
tree | 7d9b2752b6021d7653d426bbebdc80a437624a47 /src/base_object.h | |
parent | e53275d819fb21d4bb15a27a714f134551233cf9 (diff) |
src: prevent persistent handle resource leaks
Replace v8::Persistent with node::Persistent, a specialization that
resets the persistent handle on destruction. Prevents accidental
resource leaks when forgetting to call .Reset() manually.
I'm fairly confident this commit fixes a number of resource leaks that
have gone undiagnosed so far.
PR-URL: https://github.com/nodejs/node/pull/18656
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/base_object.h')
-rw-r--r-- | src/base_object.h | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/base_object.h b/src/base_object.h index 965683d029e..0640f91cbf5 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -24,6 +24,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS +#include "node_persistent.h" #include "v8.h" namespace node { @@ -39,12 +40,7 @@ class BaseObject { // persistent.IsEmpty() is true. inline v8::Local<v8::Object> object(); - // The parent class is responsible for calling .Reset() on destruction - // when the persistent handle is strong because there is no way for - // BaseObject to know when the handle goes out of scope. - // Weak handles have been reset by the time the destructor runs but - // calling .Reset() again is harmless. - inline v8::Persistent<v8::Object>& persistent(); + inline Persistent<v8::Object>& persistent(); inline Environment* env() const; @@ -71,7 +67,7 @@ class BaseObject { // position of members in memory are predictable. For more information please // refer to `doc/guides/node-postmortem-support.md` friend int GenDebugSymbols(); - v8::Persistent<v8::Object> persistent_handle_; + Persistent<v8::Object> persistent_handle_; Environment* env_; }; |