GeezerVison is showing github.com — src: cleanup DestroyParam when Environment exits · nodejs/node@aaf94fd
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/async_wrap.cc +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -348,6 +348,10 @@ class DestroyParam { |
348 | 348 | Global<Object> propBag; |
349 | 349 | }; |
350 | 350 |
|
| 351 | +static void DestroyParamCleanupHook(void* ptr) { |
| 352 | + delete static_cast<DestroyParam*>(ptr); |
| 353 | +} |
| 354 | + |
351 | 355 | void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) { |
352 | 356 | HandleScope scope(info.GetIsolate()); |
353 | 357 |
|
@@ -356,6 +360,8 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) { |
356 | 360 | p->propBag); |
357 | 361 | Local<Value> val; |
358 | 362 |
|
| 363 | + p->env->RemoveCleanupHook(DestroyParamCleanupHook, p.get()); |
| 364 | + |
359 | 365 | if (!prop_bag->Get(p->env->context(), p->env->destroyed_string()) |
360 | 366 | .ToLocal(&val)) { |
361 | 367 | return; |
@@ -380,6 +386,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) { |
380 | 386 | p->target.Reset(isolate, args[0].As<Object>()); |
381 | 387 | p->propBag.Reset(isolate, args[2].As<Object>()); |
382 | 388 | p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter); |
| 389 | + p->env->AddCleanupHook(DestroyParamCleanupHook, p); |
383 | 390 | } |
384 | 391 |
|
385 | 392 |
|
|