From 11d6a00bece86e5b2230ef043e05aefbc28191a4 Mon Sep 17 00:00:00 2001 From: d-komarov Date: Tue, 11 Jul 2017 07:35:34 +0300 Subject: [PATCH] fix storage destruction order issue (#2138) back-ported from b553cb32f785775b527bd53ea0153400c488e45e --- include/libtorrent/torrent.hpp | 4 ++++ src/torrent.cpp | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1f3c2ada7..1fc0329f2 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1168,6 +1168,10 @@ namespace libtorrent void on_file_renamed(disk_io_job const* j); void on_cache_flushed(disk_io_job const* j); + // this is used when a torrent is being removed.It synchronizes with the + // disk thread + void on_torrent_aborted(); + // upload and download rate limits for the torrent void set_limit_impl(int limit, int channel, bool state_update = true); int limit_impl(int channel) const; diff --git a/src/torrent.cpp b/src/torrent.cpp index 1a82dfbae..fa5f8660b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5003,9 +5003,8 @@ namespace libtorrent // the torrent object from there if (m_storage.get()) { - inc_refcount("release_files"); m_ses.disk_thread().async_stop_torrent(m_storage.get() - , boost::bind(&torrent::on_cache_flushed, shared_from_this(), _1)); + , boost::bind(&torrent::on_torrent_aborted, shared_from_this())); } else { @@ -5014,8 +5013,6 @@ namespace libtorrent alerts().emplace_alert(get_handle()); } - m_storage.reset(); - // TODO: 2 abort lookups this torrent has made via the // session host resolver interface @@ -9821,6 +9818,15 @@ namespace libtorrent alerts().emplace_alert(get_handle()); } + void torrent::on_torrent_aborted() + { + TORRENT_ASSERT(is_single_thread()); + + // there should be no more disk activity for this torrent now, we can + // release the disk io handle + m_storage.reset(); + } + bool torrent::is_paused() const { return !m_allow_peers || m_ses.is_paused() || m_graceful_pause_mode;