From 83e0bb6e3506476ddfb4d0aba6b124caae48bce0 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 26 Nov 2024 01:47:41 +0700 Subject: [PATCH] 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);