mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-19 20:20:00 +01:00
ArgsManager: return path by value from GetBlocksDirPath()
`ArgsManager::m_cached_blocks_path` is protected by
`ArgsManager::cs_args` and returning a reference to it after releasing
the mutex is unsafe.
To resolve this, return a copy of the path. This has some performance
penalty which is presumably ok, given that paths are a few 100s bytes
at most and `GetBlocksDirPath()` is not called often.
This silences the following (clang 18):
```
common/args.cpp:288:31: error: returning variable 'm_cached_blocks_path' by reference requires holding mutex 'cs_args' [-Werror,-Wthread-safety-reference-return]
288 | if (!path.empty()) return path;
| ^
```
Do the same with
`ArgsManager::GetDataDir()`,
`ArgsManager::GetDataDirBase()` and
`ArgsManager::GetDataDirNet()`.
This commit is contained in:
@@ -277,7 +277,7 @@ fs::path ArgsManager::GetPathArg(std::string arg, const fs::path& default_value)
|
||||
return result.has_filename() ? result : result.parent_path();
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetBlocksDirPath() const
|
||||
fs::path ArgsManager::GetBlocksDirPath() const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
fs::path& path = m_cached_blocks_path;
|
||||
@@ -302,7 +302,7 @@ const fs::path& ArgsManager::GetBlocksDirPath() const
|
||||
return path;
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetDataDir(bool net_specific) const
|
||||
fs::path ArgsManager::GetDataDir(bool net_specific) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
|
||||
|
||||
Reference in New Issue
Block a user