potential memory corruption fix when connections close when the disk becomes available

This commit is contained in:
Arvid Norberg 2010-12-04 23:24:42 +00:00
parent 1c99bf1de3
commit 03bd547f40
1 changed files with 11 additions and 4 deletions

View File

@ -2180,17 +2180,24 @@ namespace aux {
{
TORRENT_ASSERT(is_network_thread());
std::vector<peer_connection*> 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<peer_connection> 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<peer_connection*>::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();
}
}