From 83e0bb6e3506476ddfb4d0aba6b124caae48bce0 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 26 Nov 2024 01:47:41 +0700 Subject: [PATCH 1/2] fix: potential bug due to unspecified state of std::vector after move --- src/llmq/signing.cpp | 6 ++---- src/llmq/signing_shares.cpp | 5 +---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/llmq/signing.cpp b/src/llmq/signing.cpp index 9aa5a72ec8..edc8e2f74a 100644 --- a/src/llmq/signing.cpp +++ b/src/llmq/signing.cpp @@ -520,10 +520,8 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify( void CSigningManager::ProcessPendingReconstructedRecoveredSigs() { decltype(pendingReconstructedRecoveredSigs) m; - { - LOCK(cs_pending); - m = std::move(pendingReconstructedRecoveredSigs); - } + WITH_LOCK(cs_pending, swap(m, pendingReconstructedRecoveredSigs)); + for (const auto& p : m) { ProcessRecoveredSig(p.second); } diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index 3f522a121b..6cfb8d1655 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -1490,10 +1490,7 @@ void CSigSharesManager::AsyncSign(const CQuorumCPtr& quorum, const uint256& id, void CSigSharesManager::SignPendingSigShares() { std::vector v; - { - LOCK(cs_pendingSigns); - v = std::move(pendingSigns); - } + WITH_LOCK(cs_pendingSigns, v.swap(pendingSigns)); for (const auto& [pQuorum, id, msgHash] : v) { auto opt_sigShare = CreateSigShare(pQuorum, id, msgHash); From 6f75a7f601c2b8da47e07c4493b858a7ee91bc21 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 27 Nov 2024 01:13:43 +0700 Subject: [PATCH 2/2] refactor: use swap instead assign+clean in GetAndClearDirtyGovernanceObjectHashes --- src/masternode/meta.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/masternode/meta.cpp b/src/masternode/meta.cpp index c8499c5cb6..4c2ef7889c 100644 --- a/src/masternode/meta.cpp +++ b/src/masternode/meta.cpp @@ -122,9 +122,8 @@ void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObject std::vector CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes() { - LOCK(cs); - std::vector vecTmp = std::move(vecDirtyGovernanceObjectHashes); - vecDirtyGovernanceObjectHashes.clear(); + std::vector vecTmp; + WITH_LOCK(cs, vecTmp.swap(vecDirtyGovernanceObjectHashes)); return vecTmp; }