★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/13377a0f0fNouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files
src: cleanup DestroyParam when Environment exits
Otherwise, this leaks memory if the weak callback is never called.

PR-URL: #32421
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Mar 30, 2020
1 parent eda165f commit 13377a0f0fa8b7db93ba520a04a1fbf74424fb0a
Showing with 7 additions and 0 deletions.
  1. +7 −0 src/async_wrap.cc
@@ -350,6 +350,10 @@ class DestroyParam {
Global<Object> propBag;
};

static void DestroyParamCleanupHook(void* ptr) {
delete static_cast<DestroyParam*>(ptr);
}

void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
HandleScope scope(info.GetIsolate());

@@ -358,6 +362,8 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
p->propBag);
Local<Value> val;

p->env->RemoveCleanupHook(DestroyParamCleanupHook, p.get());

if (!prop_bag->Get(p->env->context(), p->env->destroyed_string())
.ToLocal(&val)) {
return;
@@ -382,6 +388,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
p->target.Reset(isolate, args[0].As<Object>());
p->propBag.Reset(isolate, args[2].As<Object>());
p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter);
p->env->AddCleanupHook(DestroyParamCleanupHook, p);
}

void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) {

0 comments on commit 13377a0

Please sign in to comment.