diff --git a/src/util.cpp b/src/util.cpp index e58ff042e8a..3bb52e9b3dd 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -871,8 +871,10 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) { - LOCK(cs_args); - m_config_args.clear(); + { + LOCK(cs_args); + m_config_args.clear(); + } const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME); fs::ifstream stream(GetConfigFile(confPath)); @@ -884,7 +886,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) } // if there is an -includeconf in the override args, but it is empty, that means the user // passed '-noincludeconf' on the command line, in which case we should not include anything - if (m_override_args.count("-includeconf") == 0) { + bool emptyIncludeConf; + { + LOCK(cs_args); + emptyIncludeConf = m_override_args.count("-includeconf") == 0; + } + if (emptyIncludeConf) { std::string chain_id = GetChainName(); std::vector includeconf(GetArgs("-includeconf")); { @@ -896,8 +903,11 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) // Remove -includeconf from configuration, so we can warn about recursion // later - m_config_args.erase("-includeconf"); - m_config_args.erase(std::string("-") + chain_id + ".includeconf"); + { + LOCK(cs_args); + m_config_args.erase("-includeconf"); + m_config_args.erase(std::string("-") + chain_id + ".includeconf"); + } for (const std::string& to_include : includeconf) { fs::ifstream include_config(GetConfigFile(to_include));