From fb3049a0ebdb153bc45692271eed68353fb8b745 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 28 Jun 2010 01:30:59 +0000 Subject: [PATCH] fixed rare crash when purging the peer list --- ChangeLog | 1 + src/policy.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b8782ebe..5858ee2b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,7 @@ incoming connection * added more detailed instrumentation of the disk I/O thread + * fixed rare crash when purging the peer list * fixed race condition around m_abort in session_impl * fixed bug in web_peer_connection which could cause a hang when downloading from web servers diff --git a/src/policy.cpp b/src/policy.cpp index c8c2e6cf7..76d92dbc6 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -382,6 +382,7 @@ namespace libtorrent } TORRENT_ASSERT(m_num_connect_candidates < m_peers.size()); if (m_round_robin > i - m_peers.begin()) --m_round_robin; + if (m_round_robin >= m_peers.size()) m_round_robin = 0; #if TORRENT_USE_IPV6 if ((*i)->is_v6_addr) @@ -538,7 +539,7 @@ namespace libtorrent external_ip = address_v4(bytes); } - if (m_round_robin == m_peers.size()) m_round_robin = 0; + if (m_round_robin >= m_peers.size()) m_round_robin = 0; #ifndef TORRENT_DISABLE_DHT bool pinged = false; @@ -551,7 +552,7 @@ namespace libtorrent for (int iterations = (std::min)(int(m_peers.size()), 300); iterations > 0; --iterations) { - if (m_round_robin == int(m_peers.size())) m_round_robin = 0; + if (m_round_robin >= int(m_peers.size())) m_round_robin = 0; peer& pe = *m_peers[m_round_robin]; int current = m_round_robin; @@ -778,7 +779,6 @@ namespace libtorrent return false; } - if (m_round_robin > iter - m_peers.begin()) ++m_round_robin; #if TORRENT_USE_IPV6 bool is_v6 = c.remote().address().is_v6(); #endif @@ -804,6 +804,8 @@ namespace libtorrent iter = m_peers.insert(iter, p); + if (m_round_robin >= iter - m_peers.begin()) ++m_round_robin; + i = *iter; #ifndef TORRENT_DISABLE_GEO_IP int as = ses.as_for_ip(c.remote().address()); @@ -962,10 +964,10 @@ namespace libtorrent , p->address(), peer_address_compare()); } - if (m_round_robin > iter - m_peers.begin()) ++m_round_robin; - iter = m_peers.insert(iter, p); + if (m_round_robin >= iter - m_peers.begin()) ++m_round_robin; + #ifndef TORRENT_DISABLE_ENCRYPTION if (flags & 0x01) p->pe_support = true; #endif