Skip to content

Commit 1e29379

Browse files
Fix potential deadlock
1 parent d58dc9f commit 1e29379

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/util.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,10 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
871871

872872
bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
873873
{
874-
LOCK(cs_args);
875-
m_config_args.clear();
874+
{
875+
LOCK(cs_args);
876+
m_config_args.clear();
877+
}
876878

877879
const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME);
878880
fs::ifstream stream(GetConfigFile(confPath));
@@ -884,7 +886,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
884886
}
885887
// if there is an -includeconf in the override args, but it is empty, that means the user
886888
// passed '-noincludeconf' on the command line, in which case we should not include anything
887-
if (m_override_args.count("-includeconf") == 0) {
889+
bool emptyIncludeConf;
890+
{
891+
LOCK(cs_args);
892+
emptyIncludeConf = m_override_args.count("-includeconf") == 0;
893+
}
894+
if (emptyIncludeConf) {
888895
std::string chain_id = GetChainName();
889896
std::vector<std::string> includeconf(GetArgs("-includeconf"));
890897
{
@@ -896,8 +903,11 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
896903

897904
// Remove -includeconf from configuration, so we can warn about recursion
898905
// later
899-
m_config_args.erase("-includeconf");
900-
m_config_args.erase(std::string("-") + chain_id + ".includeconf");
906+
{
907+
LOCK(cs_args);
908+
m_config_args.erase("-includeconf");
909+
m_config_args.erase(std::string("-") + chain_id + ".includeconf");
910+
}
901911

902912
for (const std::string& to_include : includeconf) {
903913
fs::ifstream include_config(GetConfigFile(to_include));

0 commit comments

Comments
 (0)