diff --git a/ChangeLog b/ChangeLog index a941090ec..abdd486cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,8 @@ release 0.14.3 * fixed bug where an asio exception could be thrown when resolving peer countries * fixed crash when shutting down while checking a torrent + * fixed potential crash in connection_queue when a peer_connection + fail to open its socket release 0.14.2 diff --git a/src/connection_queue.cpp b/src/connection_queue.cpp index 02f813cf8..131ec9725 100644 --- a/src/connection_queue.cpp +++ b/src/connection_queue.cpp @@ -1,4 +1,3 @@ - /* Copyright (c) 2007, Arvid Norberg @@ -177,6 +176,9 @@ namespace libtorrent std::list::iterator i = std::find_if(m_queue.begin() , m_queue.end(), boost::bind(&entry::connecting, _1) == false); + + std::list to_connect; + while (i != m_queue.end()) { TORRENT_ASSERT(i->connecting == false); @@ -193,15 +195,7 @@ namespace libtorrent INVARIANT_CHECK; - entry& ent = *i; - ++i; -#ifndef BOOST_NO_EXCEPTIONS - try { -#endif - ent.on_connect(ent.ticket); -#ifndef BOOST_NO_EXCEPTIONS - } catch (std::exception&) {} -#endif + to_connect.push_back(*i); #ifdef TORRENT_CONNECTION_LOGGING m_log << log_time() << " " << free_slots() << std::endl; @@ -211,6 +205,19 @@ namespace libtorrent && m_half_open_limit > 0) break; i = std::find_if(i, m_queue.end(), boost::bind(&entry::connecting, _1) == false); } + + while (!to_connect.empty()) + { + entry& ent = to_connect.front(); +#ifndef BOOST_NO_EXCEPTIONS + try { +#endif + ent.on_connect(ent.ticket); +#ifndef BOOST_NO_EXCEPTIONS + } catch (std::exception&) {} +#endif + to_connect.pop_front(); + } } #ifdef TORRENT_DEBUG