aboutsummaryrefslogtreecommitdiff
path: root/src/common/args.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2023-11-02 13:20:17 +0100
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-12-11 17:42:17 +0100
commit856c88776f8486446602476a1c9e133ac0cff510 (patch)
tree9dd2e04829462d88444ae95650f25613d515125d /src/common/args.h
parentfa3d9304e80c214c8b073f12a7f4b08c5a94af04 (diff)
downloadbitcoin-856c88776f8486446602476a1c9e133ac0cff510.tar.xz
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()`.
Diffstat (limited to 'src/common/args.h')
-rw-r--r--src/common/args.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/args.h b/src/common/args.h
index 1c5db718f4..6451b194d1 100644
--- a/src/common/args.h
+++ b/src/common/args.h
@@ -215,21 +215,21 @@ protected:
*
* @return Blocks path which is network specific
*/
- const fs::path& GetBlocksDirPath() const;
+ fs::path GetBlocksDirPath() const;
/**
* Get data directory path
*
* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned
*/
- const fs::path& GetDataDirBase() const { return GetDataDir(false); }
+ fs::path GetDataDirBase() const { return GetDataDir(false); }
/**
* Get data directory path with appended network identifier
*
* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned
*/
- const fs::path& GetDataDirNet() const { return GetDataDir(true); }
+ fs::path GetDataDirNet() const { return GetDataDir(true); }
/**
* Clear cached directory paths
@@ -420,7 +420,7 @@ private:
* @param net_specific Append network identifier to the returned path
* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned
*/
- const fs::path& GetDataDir(bool net_specific) const;
+ fs::path GetDataDir(bool net_specific) const;
/**
* Return -regtest/-signet/-testnet/-chain= setting as a ChainType enum if a