mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix crash inside OverlayImpl loops over ids_ (#5071)
This commit is contained in:
@@ -189,7 +189,10 @@ private:
|
|||||||
consumer,
|
consumer,
|
||||||
std::move(stream_ptr),
|
std::move(stream_ptr),
|
||||||
overlay);
|
overlay);
|
||||||
|
BEAST_EXPECT(
|
||||||
|
overlay.findPeerByPublicKey(key) == std::shared_ptr<PeerImp>{});
|
||||||
overlay.add_active(peer);
|
overlay.add_active(peer);
|
||||||
|
BEAST_EXPECT(overlay.findPeerByPublicKey(key) == peer);
|
||||||
peers.emplace_back(peer); // overlay stores week ptr to PeerImp
|
peers.emplace_back(peer); // overlay stores week ptr to PeerImp
|
||||||
lid_ += 2;
|
lid_ += 2;
|
||||||
rid_ += 2;
|
rid_ += 2;
|
||||||
|
|||||||
@@ -1163,9 +1163,11 @@ OverlayImpl::getActivePeers(
|
|||||||
disabled = enabledInSkip = 0;
|
disabled = enabledInSkip = 0;
|
||||||
ret.reserve(ids_.size());
|
ret.reserve(ids_.size());
|
||||||
|
|
||||||
|
// NOTE The purpose of p is to delay the destruction of PeerImp
|
||||||
|
std::shared_ptr<PeerImp> p;
|
||||||
for (auto& [id, w] : ids_)
|
for (auto& [id, w] : ids_)
|
||||||
{
|
{
|
||||||
if (auto p = w.lock())
|
if (p = w.lock(); p != nullptr)
|
||||||
{
|
{
|
||||||
bool const reduceRelayEnabled = p->txReduceRelayEnabled();
|
bool const reduceRelayEnabled = p->txReduceRelayEnabled();
|
||||||
// tx reduced relay feature disabled
|
// tx reduced relay feature disabled
|
||||||
@@ -1205,9 +1207,11 @@ std::shared_ptr<Peer>
|
|||||||
OverlayImpl::findPeerByPublicKey(PublicKey const& pubKey)
|
OverlayImpl::findPeerByPublicKey(PublicKey const& pubKey)
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex_);
|
std::lock_guard lock(mutex_);
|
||||||
|
// NOTE The purpose of peer is to delay the destruction of PeerImp
|
||||||
|
std::shared_ptr<PeerImp> peer;
|
||||||
for (auto const& e : ids_)
|
for (auto const& e : ids_)
|
||||||
{
|
{
|
||||||
if (auto peer = e.second.lock())
|
if (peer = e.second.lock(); peer != nullptr)
|
||||||
{
|
{
|
||||||
if (peer->getNodePublic() == pubKey)
|
if (peer->getNodePublic() == pubKey)
|
||||||
return peer;
|
return peer;
|
||||||
|
|||||||
Reference in New Issue
Block a user