From 8f4e722f730a3b3bec0b6c461fbe7b32058ed21f Mon Sep 17 00:00:00 2001 From: David Schwartz Date: Tue, 24 Sep 2013 16:46:25 -0700 Subject: [PATCH] Protect mRecentLedgers/mRecentTxSets with a mutex. --- src/ripple_app/peers/Peer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ripple_app/peers/Peer.cpp b/src/ripple_app/peers/Peer.cpp index 9c2b3492f..4c44b0acb 100644 --- a/src/ripple_app/peers/Peer.cpp +++ b/src/ripple_app/peers/Peer.cpp @@ -98,8 +98,10 @@ private: uint256 mClosedLedgerHash; uint256 mPreviousLedgerHash; + std::list mRecentLedgers; std::list mRecentTxSets; + boost::mutex mRecentLock; boost::asio::deadline_timer mActivityTimer; @@ -2276,7 +2278,9 @@ void PeerImp::recvLedger (const boost::shared_ptr& packe } bool PeerImp::hasLedger (uint256 const& hash, uint32 seq) const -{ // FIXME: mRecentLedgers needs some kind of synchronization +{ + boost::mutex::scoped_lock sl(mRecentLock); + if ((seq != 0) && (seq >= mMinLedger) && (seq <= mMaxLedger)) return true; @@ -2291,6 +2295,7 @@ bool PeerImp::hasLedger (uint256 const& hash, uint32 seq) const void PeerImp::addLedger (uint256 const& hash) { + boost::mutex::scoped_lock sl(mRecentLock); BOOST_FOREACH (uint256 const & ledger, mRecentLedgers) if (ledger == hash) @@ -2304,6 +2309,7 @@ void PeerImp::addLedger (uint256 const& hash) bool PeerImp::hasTxSet (uint256 const& hash) const { + boost::mutex::scoped_lock sl(mRecentLock); BOOST_FOREACH (uint256 const & set, mRecentTxSets) if (set == hash) @@ -2314,6 +2320,7 @@ bool PeerImp::hasTxSet (uint256 const& hash) const void PeerImp::addTxSet (uint256 const& hash) { + boost::mutex::scoped_lock sl(mRecentLock); BOOST_FOREACH (uint256 const & set, mRecentTxSets) if (set == hash)