From 03bd547f40aba72d352de0355234d1ed0e97c92f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 4 Dec 2010 23:24:42 +0000 Subject: [PATCH] potential memory corruption fix when connections close when the disk becomes available --- src/session_impl.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 197443158..7bc3e4613 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2180,17 +2180,24 @@ namespace aux { { TORRENT_ASSERT(is_network_thread()); + std::vector conns; + conns.reserve(m_connections.size() / 2); for (connection_map::iterator i = m_connections.begin(); - i != m_connections.end();) + i != m_connections.end(); ++i) { - boost::intrusive_ptr p = *i; - ++i; + peer_connection* p = i->get(); if (p->m_channel_state[peer_connection::download_channel] != peer_info::bw_disk) continue; + conns.push_back(p); + } + + for (std::vector::iterator i = conns.begin() + , end(conns.end()); i != end; ++i) + { // setup_receive() may disconnect the connection // and clear it out from the m_connections list - p->setup_receive(); + (*i)->setup_receive(); } }