From 56a45095b71f4ebcf5405f83ab5af665452289db Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 22 Jan 2020 23:33:29 +0100 Subject: [PATCH] src: harden running native `SetImmediate()`s slightly Prevent mistakes like the one fixed by the previous commit by destroying the callback immediately after it has been called. Backport-PR-URL: https://github.com/nodejs/node/pull/32301 PR-URL: https://github.com/nodejs/node/pull/31468 Refs: https://github.com/nodejs/node/pull/31386 Reviewed-By: Colin Ihrig Reviewed-By: Gireesh Punathil --- src/env.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/env.cc b/src/env.cc index 684e183b853234..2bdac964cb03ca 100644 --- a/src/env.cc +++ b/src/env.cc @@ -698,6 +698,8 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { if (head->is_refed() || !only_refed) head->Call(this); + head.reset(); // Destroy now so that this is also observed by try_catch. + if (UNLIKELY(try_catch.HasCaught())) { if (!try_catch.HasTerminated() && can_call_into_js()) errors::TriggerUncaughtException(isolate(), try_catch);