Skip to content

Commit

Permalink
src: guard against calling Init() multiple times
Browse files Browse the repository at this point in the history
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: nodejs#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>
  • Loading branch information
addaleax committed Mar 9, 2019
1 parent 3afa5d7 commit 97ce5e0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,14 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
return 0;
}

static std::atomic_bool init_called{false};

int Init(std::vector<std::string>* argv,
std::vector<std::string>* exec_argv,
std::vector<std::string>* errors) {
// Make sure Init() is called only once.
CHECK(!init_called.exchange(true));

// Register built-in modules
binding::RegisterBuiltinModules();

Expand Down

0 comments on commit 97ce5e0

Please sign in to comment.