make sure the cork destructor doesn't leak exceptions

This commit is contained in:
arvidn 2017-11-11 16:33:48 +01:00 committed by Arvid Norberg
parent 0378ae47f4
commit 521587c026
2 changed files with 23 additions and 3 deletions

View File

@ -680,6 +680,8 @@ namespace aux {
std::shared_ptr<peer_connection> self()
{
TORRENT_ASSERT(!m_destructed);
TORRENT_ASSERT(m_in_use == 1337);
TORRENT_ASSERT(!m_in_constructor);
return shared_from_this();
}
@ -1202,8 +1204,21 @@ namespace aux {
~cork()
{
if (!m_need_uncork) return;
m_pc.m_channel_state[peer_connection::upload_channel] &= ~peer_info::bw_network;
m_pc.setup_send();
try {
m_pc.m_channel_state[peer_connection::upload_channel] &= ~peer_info::bw_network;
m_pc.setup_send();
}
catch (std::bad_alloc const&) {
m_pc.disconnect(make_error_code(boost::system::errc::not_enough_memory)
, operation_t::sock_write);
}
catch (boost::system::system_error const& err) {
m_pc.disconnect(err.code(), operation_t::sock_write);
}
catch (...) {
m_pc.disconnect(make_error_code(boost::system::errc::not_enough_memory)
, operation_t::sock_write);
}
}
private:
peer_connection& m_pc;

View File

@ -4104,7 +4104,7 @@ namespace libtorrent {
torrent_peer* self_peer = peer_info_struct();
#ifndef TORRENT_DISABLE_LOGGING
if (should_log(peer_log_alert::info))
if (should_log(peer_log_alert::info)) try
{
switch (error)
{
@ -4130,6 +4130,11 @@ namespace libtorrent {
peer_log(peer_log_alert::info, "SHORT_LIVED_DISCONNECT", "");
}
}
catch (std::exception const& err)
{
peer_log(peer_log_alert::info, "PEER_ERROR" ,"op: %d error: unknown error (failed with exception) %s"
, static_cast<int>(op), err.what());
}
#endif
if (!(m_channel_state[upload_channel] & peer_info::bw_network))