summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-07-11 00:12:02 +0200
committerMichaël Zasso <targos@protonmail.com>2019-07-20 11:10:26 +0200
commit5c1d5958e03941b37662bbd4704ff82af565eb46 (patch)
treefc6594d6a693d70df5fd77baf4bcd8b30e2f52ca /src
parent03de3062817dcf826d65a0242cf50adc04255c3c (diff)
downloadandroid-node-v8-5c1d5958e03941b37662bbd4704ff82af565eb46.tar.gz
android-node-v8-5c1d5958e03941b37662bbd4704ff82af565eb46.tar.bz2
android-node-v8-5c1d5958e03941b37662bbd4704ff82af565eb46.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>
Diffstat (limited to 'src')
-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,