From 31b31a3c52376a62bb1cd706dfc116c881fea12c 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. 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 ba5e9cd5a05218..19c29c2fcab950 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);