From ecb9b2b725e547534334b030bc12a8b2c0833305 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 21 Apr 2012 03:49:27 +0000 Subject: [PATCH] fixed possible crash when enabling multiple connections per IP --- ChangeLog | 1 + src/policy.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 735f4b30a..12d9a9ac5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * fixed possible crash when enabling multiple connections per IP * fixed typo in win vista specific code, breaking the build * change default of rate_limit_utp to true * fixed DLL export issue on windows (when building a shared library linking statically against boost) diff --git a/src/policy.cpp b/src/policy.cpp index 281d96e28..c0873422a 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -1029,6 +1029,14 @@ namespace libtorrent pp.source |= src; if (!was_conn_cand && is_connect_candidate(pp, m_finished)) ++m_num_connect_candidates; + // calling disconnect() on a peer, may actually end + // up "garbage collecting" its policy::peer entry + // as well, if it's considered useless (which this specific) + // case will, since it was an incoming peer that just disconnected + // and we allow multiple connections per IP. Because of that, + // we need to make sure we don't let it do that, by unlinking + // the peer_connection from the policy::peer first. + p->connection->set_peer_info(0); p->connection->disconnect(errors::duplicate_peer_id); erase_peer(p); return false;