Skip to content

Commit 4e04814

Browse files
committed
Lock mapArgs/mapMultiArgs access in util
1 parent 4cd373a commit 4e04814

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/util.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ using namespace std;
102102
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
103103
const char * const BITCOIN_PID_FILENAME = "bitcoind.pid";
104104

105+
CCriticalSection cs_args;
105106
map<string, string> mapArgs;
106107
static map<string, vector<string> > _mapMultiArgs;
107108
const map<string, vector<string> >& mapMultiArgs = _mapMultiArgs;
@@ -346,6 +347,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue)
346347

347348
void ParseParameters(int argc, const char* const argv[])
348349
{
350+
LOCK(cs_args);
349351
mapArgs.clear();
350352
_mapMultiArgs.clear();
351353

@@ -381,32 +383,37 @@ void ParseParameters(int argc, const char* const argv[])
381383

382384
bool IsArgSet(const std::string& strArg)
383385
{
386+
LOCK(cs_args);
384387
return mapArgs.count(strArg);
385388
}
386389

387390
std::string GetArg(const std::string& strArg, const std::string& strDefault)
388391
{
392+
LOCK(cs_args);
389393
if (mapArgs.count(strArg))
390394
return mapArgs[strArg];
391395
return strDefault;
392396
}
393397

394398
int64_t GetArg(const std::string& strArg, int64_t nDefault)
395399
{
400+
LOCK(cs_args);
396401
if (mapArgs.count(strArg))
397402
return atoi64(mapArgs[strArg]);
398403
return nDefault;
399404
}
400405

401406
bool GetBoolArg(const std::string& strArg, bool fDefault)
402407
{
408+
LOCK(cs_args);
403409
if (mapArgs.count(strArg))
404410
return InterpretBool(mapArgs[strArg]);
405411
return fDefault;
406412
}
407413

408414
bool SoftSetArg(const std::string& strArg, const std::string& strValue)
409415
{
416+
LOCK(cs_args);
410417
if (mapArgs.count(strArg))
411418
return false;
412419
mapArgs[strArg] = strValue;
@@ -522,6 +529,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
522529

523530
void ClearDatadirCache()
524531
{
532+
LOCK(csPathCached);
533+
525534
pathCached = boost::filesystem::path();
526535
pathCachedNetSpecific = boost::filesystem::path();
527536
}
@@ -541,18 +550,21 @@ void ReadConfigFile(const std::string& confPath)
541550
if (!streamConfig.good())
542551
return; // No bitcoin.conf file is OK
543552

544-
set<string> setOptions;
545-
setOptions.insert("*");
546-
547-
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
548553
{
549-
// Don't overwrite existing settings so command line settings override bitcoin.conf
550-
string strKey = string("-") + it->string_key;
551-
string strValue = it->value[0];
552-
InterpretNegativeSetting(strKey, strValue);
553-
if (mapArgs.count(strKey) == 0)
554-
mapArgs[strKey] = strValue;
555-
_mapMultiArgs[strKey].push_back(strValue);
554+
LOCK(cs_args);
555+
set<string> setOptions;
556+
setOptions.insert("*");
557+
558+
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
559+
{
560+
// Don't overwrite existing settings so command line settings override bitcoin.conf
561+
string strKey = string("-") + it->string_key;
562+
string strValue = it->value[0];
563+
InterpretNegativeSetting(strKey, strValue);
564+
if (mapArgs.count(strKey) == 0)
565+
mapArgs[strKey] = strValue;
566+
_mapMultiArgs[strKey].push_back(strValue);
567+
}
556568
}
557569
// If datadir is changed in .conf file:
558570
ClearDatadirCache();

0 commit comments

Comments
 (0)