clear alert nofify function when calling abort on a session, to avoid touching a destructed session object (#1015)

This commit is contained in:
Arvid Norberg 2016-08-20 11:04:44 -04:00 committed by GitHub
parent e247473b86
commit b701fb252a
11 changed files with 13 additions and 10 deletions

View File

@ -281,7 +281,7 @@ namespace libtorrent
// session_proxy(); // session_proxy();
// ~session_proxy() // ~session_proxy()
// }; // };
session_proxy abort() { return session_proxy(m_io_service, m_thread, m_impl); } session_proxy abort();
private: private:

View File

@ -69,7 +69,6 @@ void run_test(Setup const& setup, Test const& test)
test(*ses); test(*ses);
// shut down // shut down
ses->set_alert_notify([]{});
zombie = ses->abort(); zombie = ses->abort();
ses.reset(); ses.reset();
}); });

View File

@ -79,7 +79,6 @@ void run_fake_peer_test(
sim::timer t(sim, lt::seconds(1) sim::timer t(sim, lt::seconds(1)
, [&](boost::system::error_code const& ec) , [&](boost::system::error_code const& ec)
{ {
ses->set_alert_notify([]{});
// shut down // shut down
zombie = ses->abort(); zombie = ses->abort();

View File

@ -88,7 +88,6 @@ void run_test(Setup const& setup
{ {
test(*ses, test_peers); test(*ses, test_peers);
ses->set_alert_notify([]{});
// shut down // shut down
zombie = ses->abort(); zombie = ses->abort();

View File

@ -148,7 +148,6 @@ TORRENT_TEST(optimistic_unchoke)
{ {
p->abort(); p->abort();
} }
ses->set_alert_notify([]{});
proxy = ses->abort(); proxy = ses->abort();
ses.reset(); ses.reset();
}); });

View File

@ -101,7 +101,6 @@ void run_test(Setup const& setup
{ {
fprintf(stderr, "shutting down\n"); fprintf(stderr, "shutting down\n");
// shut down // shut down
ses->set_alert_notify([] {});
zombie = ses->abort(); zombie = ses->abort();
ses.reset(); ses.reset();
}); });

View File

@ -352,7 +352,6 @@ TORRENT_TEST(ipv6_support)
, [&ses,&zombie](boost::system::error_code const& ec) , [&ses,&zombie](boost::system::error_code const& ec)
{ {
zombie = ses->abort(); zombie = ses->abort();
ses->set_alert_notify([]{});
ses.reset(); ses.reset();
}); });
@ -427,7 +426,6 @@ void tracker_test(Setup setup, Announce a, Test1 test1, Test2 test2
, [&ses,&zombie](boost::system::error_code const& ec) , [&ses,&zombie](boost::system::error_code const& ec)
{ {
zombie = ses->abort(); zombie = ses->abort();
ses->set_alert_notify([]{});
ses.reset(); ses.reset();
}); });

View File

@ -139,7 +139,6 @@ void run_test(
int idx = 0; int idx = 0;
for (auto& s : ses) for (auto& s : ses)
{ {
s->set_alert_notify([]{});
zombie[idx++] = s->abort(); zombie[idx++] = s->abort();
s.reset(); s.reset();
} }

View File

@ -113,7 +113,6 @@ void run_test(Setup const& setup
{ {
fprintf(stderr, "shutting down\n"); fprintf(stderr, "shutting down\n");
// shut down // shut down
ses->set_alert_notify([] {});
zombie = ses->abort(); zombie = ses->abort();
ses.reset(); ses.reset();
}); });

View File

@ -409,6 +409,14 @@ namespace libtorrent
m_thread->join(); m_thread->join();
} }
session_proxy session::abort()
{
// stop calling the alert notify function now, to avoid it thinking the
// session is still alive
m_impl->alerts().set_notify_function(boost::function<void()>());
return session_proxy(m_io_service, m_thread, m_impl);
}
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
session_settings::session_settings(std::string const& user_agent_) session_settings::session_settings(std::string const& user_agent_)
{ {

View File

@ -1076,6 +1076,10 @@ namespace aux {
session_log(" *** ABORT CALLED ***"); session_log(" *** ABORT CALLED ***");
#endif #endif
// at this point we cannot call the notify function anymore, since the
// session will become invalid.
m_alerts.set_notify_function(boost::function<void()>());
// this will cancel requests that are not critical for shutting down // this will cancel requests that are not critical for shutting down
// cleanly. i.e. essentially tracker hostname lookups that we're not // cleanly. i.e. essentially tracker hostname lookups that we're not
// about to send event=stopped to // about to send event=stopped to