HomePhabricator

ArgsManager: return path by value from GetBlocksDirPath()

Description

ArgsManager: return path by value from GetBlocksDirPath()

Summary:

`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()`.

Partial backport of core#29040:
https://github.com/bitcoin/bitcoin/pull/29040/commits/856c88776f8486446602476a1c9e133ac0cff510

Test Plan:
With Clang 18:

ninja all check

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17012

Details

Provenance
Vasil Dimov <vd@FreeBSD.org>Authored on Nov 2 2023, 12:20
FabienCommitted on Sat, Oct 26, 18:20
FabienPushed on Sat, Oct 26, 18:20
Reviewer
Restricted Project
Differential Revision
D17012: ArgsManager: return path by value from GetBlocksDirPath()
Parents
rABC2a0a45a36489: [Cashtab] Patch misnamed mock
Branches
Unknown
Tags
Unknown