From 97ce5e0b4b614872ced69ba800bc726d464e92f2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 5 Mar 2019 20:16:33 +0100 Subject: [PATCH] src: guard against calling `Init()` multiple times This function should only be called once. Calling it multiple times would currently break Node.js (e.g. re-registering builtin modules would break the linked list for them). PR-URL: https://github.com/nodejs/node/pull/26458 Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- src/node.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node.cc b/src/node.cc index 4def46ee167dbd..89217e47bc1070 100644 --- a/src/node.cc +++ b/src/node.cc @@ -608,9 +608,14 @@ int ProcessGlobalArgs(std::vector* args, return 0; } +static std::atomic_bool init_called{false}; + int Init(std::vector* argv, std::vector* exec_argv, std::vector* errors) { + // Make sure Init() is called only once. + CHECK(!init_called.exchange(true)); + // Register built-in modules binding::RegisterBuiltinModules();