mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-04 10:45:50 +00:00
Fix crash inside OverlayImpl loops over ids_ (#5071)
This commit is contained in:
@@ -189,7 +189,10 @@ private:
|
||||
consumer,
|
||||
std::move(stream_ptr),
|
||||
overlay);
|
||||
BEAST_EXPECT(
|
||||
overlay.findPeerByPublicKey(key) == std::shared_ptr<PeerImp>{});
|
||||
overlay.add_active(peer);
|
||||
BEAST_EXPECT(overlay.findPeerByPublicKey(key) == peer);
|
||||
peers.emplace_back(peer); // overlay stores week ptr to PeerImp
|
||||
lid_ += 2;
|
||||
rid_ += 2;
|
||||
|
||||
@@ -1150,9 +1150,11 @@ OverlayImpl::getActivePeers(
|
||||
disabled = enabledInSkip = 0;
|
||||
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_)
|
||||
{
|
||||
if (auto p = w.lock())
|
||||
if (p = w.lock(); p != nullptr)
|
||||
{
|
||||
bool const reduceRelayEnabled = p->txReduceRelayEnabled();
|
||||
// tx reduced relay feature disabled
|
||||
@@ -1192,9 +1194,11 @@ std::shared_ptr<Peer>
|
||||
OverlayImpl::findPeerByPublicKey(PublicKey const& pubKey)
|
||||
{
|
||||
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_)
|
||||
{
|
||||
if (auto peer = e.second.lock())
|
||||
if (peer = e.second.lock(); peer != nullptr)
|
||||
{
|
||||
if (peer->getNodePublic() == pubKey)
|
||||
return peer;
|
||||
|
||||
Reference in New Issue
Block a user