Skip to content

Commit 1d4fd21

Browse files
addaleaxBridgeAR
authored andcommitted
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: #26458 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dcfdef5 commit 1d4fd21

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/node.cc

+5
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,14 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
608608
return 0;
609609
}
610610

611+
static std::atomic_bool init_called{false};
612+
611613
int Init(std::vector<std::string>* argv,
612614
std::vector<std::string>* exec_argv,
613615
std::vector<std::string>* errors) {
616+
// Make sure Init() is called only once.
617+
CHECK(!init_called.exchange(true));
618+
614619
// Register built-in modules
615620
binding::RegisterBuiltinModules();
616621

0 commit comments

Comments
 (0)