From 6ee8c98862157216ff20e76754bfd76f709777dd Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 12 Aug 2021 11:50:58 +0300 Subject: [PATCH] PeerContext is used after being deleted, keep shared pointer to it. (#161) Signed-off-by: Alexey-N-Chernyshov --- src/protocol/gossip/impl/connectivity.cpp | 4 ++-- src/protocol/gossip/impl/stream.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/protocol/gossip/impl/connectivity.cpp b/src/protocol/gossip/impl/connectivity.cpp index 10dfa15e..85aea2f0 100644 --- a/src/protocol/gossip/impl/connectivity.cpp +++ b/src/protocol/gossip/impl/connectivity.cpp @@ -50,9 +50,9 @@ namespace libp2p::protocol::gossip { // clang-format off on_stream_event_ = [this, self_wptr=weak_from_this()] - (const PeerContextPtr &from, outcome::result event) { + (PeerContextPtr from, outcome::result event) { if (self_wptr.expired()) return; - onStreamEvent(from, event); + onStreamEvent(std::move(from), event); }; host_->setProtocolHandler( diff --git a/src/protocol/gossip/impl/stream.hpp b/src/protocol/gossip/impl/stream.hpp index c94e6713..61f0c445 100644 --- a/src/protocol/gossip/impl/stream.hpp +++ b/src/protocol/gossip/impl/stream.hpp @@ -23,7 +23,7 @@ namespace libp2p::protocol::gossip { class Stream : public std::enable_shared_from_this { public: /// Feedback interface to its owning object (i.e. pub-sub instance) - using Feedback = std::function event)>; /// Ctor. N.B. Stream instance cannot live longer than its creators