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>
This commit is contained in:
parent
518ffc1256
commit
00464b5282
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user