diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 141460dc0..073f453bc 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -56,9 +56,16 @@ struct observer : boost::noncopyable : sent(time_now()) , pool_allocator(p) , m_refs(0) - {} + { +#ifndef NDEBUG + m_in_constructor = true; +#endif + } - virtual ~observer() {} + virtual ~observer() + { + TORRENT_ASSERT(!m_in_constructor); + } // these two callbacks lets the observer add // information to the message before it's sent @@ -79,6 +86,9 @@ struct observer : boost::noncopyable udp::endpoint target_addr; ptime sent; +#ifndef NDEBUG + bool m_in_constructor; +#endif private: boost::pool<>& pool_allocator; // reference counter for intrusive_ptr diff --git a/src/kademlia/closest_nodes.cpp b/src/kademlia/closest_nodes.cpp index 1bb58050f..77e20c82e 100644 --- a/src/kademlia/closest_nodes.cpp +++ b/src/kademlia/closest_nodes.cpp @@ -102,6 +102,9 @@ void closest_nodes::invoke(node_id const& id, udp::endpoint addr) { TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(closest_nodes_observer)); observer_ptr o(new (m_rpc.allocator().malloc()) closest_nodes_observer(this, id, m_target)); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif m_rpc.invoke(messages::find_node, addr, o); } diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 1be446d6a..9d11b5aeb 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -111,6 +111,9 @@ void find_data::invoke(node_id const& id, asio::ip::udp::endpoint addr) TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(find_data_observer)); observer_ptr o(new (m_rpc.allocator().malloc()) find_data_observer(this, id, m_target)); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif m_rpc.invoke(messages::get_peers, addr, o); } diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 75e9e4bc0..be23e3cb9 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -273,8 +273,11 @@ namespace for (std::vector::const_iterator i = v.begin() , end(v.end()); i != end; ++i) { - rpc.invoke(messages::get_peers, i->addr, observer_ptr( - new (rpc.allocator().malloc()) get_peers_observer(ih, listen_port, rpc, f))); + observer_ptr o(new (rpc.allocator().malloc()) get_peers_observer(ih, listen_port, rpc, f)); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif + rpc.invoke(messages::get_peers, i->addr, o); nodes = true; } } @@ -290,6 +293,9 @@ void node_impl::add_node(udp::endpoint node) // ping the node, and if we get a reply, it // will be added to the routing table observer_ptr o(new (m_rpc.allocator().malloc()) null_observer(m_rpc.allocator())); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif m_rpc.invoke(messages::ping, node, o); } diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 0887e0ac2..8edabb2c1 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -106,6 +106,9 @@ void refresh::invoke(node_id const& nid, udp::endpoint addr) TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(refresh_observer)); observer_ptr o(new (m_rpc.allocator().malloc()) refresh_observer( this, nid, m_target)); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif m_rpc.invoke(messages::find_node, addr, o); } @@ -158,6 +161,9 @@ void refresh::invoke_pings_or_finish(bool prevent_request) TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(ping_observer)); observer_ptr o(new (m_rpc.allocator().malloc()) ping_observer( this, node.id)); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif m_rpc.invoke(messages::ping, node.addr, o); ++m_active_pings; ++m_leftover_nodes_iterator; diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index c0c1c787e..4319fc4b8 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -438,6 +438,9 @@ void rpc_manager::reply_with_ping(msg& m) TORRENT_ASSERT(allocation_size() >= sizeof(null_observer)); observer_ptr o(new (allocator().malloc()) null_observer(allocator())); +#ifndef NDEBUG + o->m_in_constructor = false; +#endif TORRENT_ASSERT(!m_transactions[m_next_transaction_id]); o->sent = time_now(); o->target_addr = m.addr;