Skip to content

Commit db5e9d3

Browse files
Add missing locks (cs_args)
1 parent 4e9a6f8 commit db5e9d3

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/util.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ ArgsManager::ArgsManager() :
372372

373373
void ArgsManager::WarnForSectionOnlyArgs()
374374
{
375+
LOCK(cs_args);
376+
375377
// if there's no section selected, don't worry
376378
if (m_network.empty()) return;
377379

@@ -400,6 +402,7 @@ void ArgsManager::WarnForSectionOnlyArgs()
400402

401403
void ArgsManager::SelectConfigNetwork(const std::string& network)
402404
{
405+
LOCK(cs_args);
403406
m_network = network;
404407
}
405408

@@ -468,6 +471,7 @@ bool ArgsManager::IsArgKnown(const std::string& key) const
468471
arg_no_net = std::string("-") + key.substr(option_index + 1, std::string::npos);
469472
}
470473

474+
LOCK(cs_args);
471475
for (const auto& arg_map : m_available_args) {
472476
if (arg_map.second.count(arg_no_net)) return true;
473477
}
@@ -571,6 +575,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
571575
eq_index = name.size();
572576
}
573577

578+
LOCK(cs_args);
574579
std::map<std::string, Arg>& arg_map = m_available_args[cat];
575580
auto ret = arg_map.emplace(name.substr(0, eq_index), Arg(name.substr(eq_index, name.size() - eq_index), help, debug_only));
576581
assert(ret.second); // Make sure an insertion actually happened
@@ -588,6 +593,7 @@ std::string ArgsManager::GetHelpMessage() const
588593
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
589594

590595
std::string usage = "";
596+
LOCK(cs_args);
591597
for (const auto& arg_map : m_available_args) {
592598
switch(arg_map.first) {
593599
case OptionsCategory::OPTIONS:
@@ -865,10 +871,8 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
865871

866872
bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
867873
{
868-
{
869-
LOCK(cs_args);
870-
m_config_args.clear();
871-
}
874+
LOCK(cs_args);
875+
m_config_args.clear();
872876

873877
const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME);
874878
fs::ifstream stream(GetConfigFile(confPath));
@@ -892,11 +896,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
892896

893897
// Remove -includeconf from configuration, so we can warn about recursion
894898
// later
895-
{
896-
LOCK(cs_args);
897-
m_config_args.erase("-includeconf");
898-
m_config_args.erase(std::string("-") + chain_id + ".includeconf");
899-
}
899+
m_config_args.erase("-includeconf");
900+
m_config_args.erase(std::string("-") + chain_id + ".includeconf");
900901

901902
for (const std::string& to_include : includeconf) {
902903
fs::ifstream include_config(GetConfigFile(to_include));
@@ -940,6 +941,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
940941

941942
std::string ArgsManager::GetChainName() const
942943
{
944+
LOCK(cs_args);
943945
bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
944946
bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
945947

src/util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ class ArgsManager
262262
/**
263263
* Clear available arguments
264264
*/
265-
void ClearArgs() { m_available_args.clear(); }
265+
void ClearArgs() {
266+
LOCK(cs_args);
267+
m_available_args.clear();
268+
}
266269

267270
/**
268271
* Get the help string

0 commit comments

Comments
 (0)