diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 10f78333003f76..e712235d861df9 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -348,6 +348,10 @@ class DestroyParam { Global propBag; }; +static void DestroyParamCleanupHook(void* ptr) { + delete static_cast(ptr); +} + void AsyncWrap::WeakCallback(const WeakCallbackInfo& info) { HandleScope scope(info.GetIsolate()); @@ -356,6 +360,8 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo& info) { p->propBag); Local val; + p->env->RemoveCleanupHook(DestroyParamCleanupHook, p.get()); + if (!prop_bag->Get(p->env->context(), p->env->destroyed_string()) .ToLocal(&val)) { return; @@ -380,6 +386,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo& args) { p->target.Reset(isolate, args[0].As()); p->propBag.Reset(isolate, args[2].As()); p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter); + p->env->AddCleanupHook(DestroyParamCleanupHook, p); }