From 1e29379d69a6db0820ae984733d1be98340e5ed0 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Thu, 30 Aug 2018 10:02:49 +0200 Subject: [PATCH] Fix potential deadlock --- src/util.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index e58ff042e..3bb52e9b3 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));