summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-07-11 00:12:02 +0200
committerAnna Henningsen <anna@addaleax.net>2019-07-14 23:23:33 +0200
commit00464b5282724a693582079244c09a1cba5d8e08 (patch)
tree81f0332cad3e0e79ec91735ff6f7760fba3be9f7
parent518ffc125680f0916635d2ed97c076dbff3bd05b (diff)
downloadandroid-node-v8-00464b5282724a693582079244c09a1cba5d8e08.tar.gz
android-node-v8-00464b5282724a693582079244c09a1cba5d8e08.tar.bz2
android-node-v8-00464b5282724a693582079244c09a1cba5d8e08.zip
src: add cleanup hook for ContextifyContext
Otherwise there’s a memory leak left by the context when the Isolate tears down without having run the weak callback. PR-URL: https://github.com/nodejs/node/pull/28631 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
-rw-r--r--src/node_contextify.cc13
-rw-r--r--src/node_contextify.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index c6b9dc18de..5be774fb91 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -114,6 +114,19 @@ ContextifyContext::ContextifyContext(
context_.Reset(env->isolate(), v8_context.ToLocalChecked());
context_.SetWeak(this, WeakCallback, WeakCallbackType::kParameter);
+ env->AddCleanupHook(CleanupHook, this);
+}
+
+
+ContextifyContext::~ContextifyContext() {
+ env()->RemoveCleanupHook(CleanupHook, this);
+}
+
+
+void ContextifyContext::CleanupHook(void* arg) {
+ ContextifyContext* self = static_cast<ContextifyContext*>(arg);
+ self->context_.Reset();
+ delete self;
}
diff --git a/src/node_contextify.h b/src/node_contextify.h
index d04bf9ea28..288b51ef56 100644
--- a/src/node_contextify.h
+++ b/src/node_contextify.h
@@ -22,6 +22,8 @@ class ContextifyContext {
ContextifyContext(Environment* env,
v8::Local<v8::Object> sandbox_obj,
const ContextOptions& options);
+ ~ContextifyContext();
+ static void CleanupHook(void* arg);
v8::MaybeLocal<v8::Object> CreateDataWrapper(Environment* env);
v8::MaybeLocal<v8::Context> CreateV8Context(Environment* env,