From adf043f5faaefef05beecbace9dca2160cbb09ff 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). --- src/node.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node.cc b/src/node.cc index cbef51960a4ebe..b4dd1a7da96277 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();