From 59deff7a44eb77bf6f9232da407a124cbd4c4488 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 21 Feb 2010 08:52:26 +0000 Subject: [PATCH] fixed issue with disk read cache not being cleared when removing torrents --- ChangeLog | 1 + include/libtorrent/torrent.hpp | 1 + src/disk_io_thread.cpp | 19 +++++++++++++++++++ src/torrent.cpp | 13 +++++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6bd059c9a..53bde4aa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -105,6 +105,7 @@ * added info_hash to torrent_deleted_alert * improved LSD performance and made the interval configurable * improved UDP tracker support by caching connect tokens + * fixed issue with disk read cache not being cleared when removing torrents release 0.14.9 diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 3745de71c..22f04b8ff 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -763,6 +763,7 @@ namespace libtorrent void on_files_deleted(int ret, disk_io_job const& j); void on_files_released(int ret, disk_io_job const& j); + void on_torrent_aborted(int ret, disk_io_job const& j); void on_torrent_paused(int ret, disk_io_job const& j); void on_storage_moved(int ret, disk_io_job const& j); void on_save_resume_data(int ret, disk_io_job const& j); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 39af9989d..352a10e58 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1650,6 +1650,25 @@ namespace libtorrent post_callback(i->second.callback, i->second, -3); sorted_read_jobs.erase(i++); } + jl.unlock(); + + mutex_t::scoped_lock l(m_piece_mutex); + + for (cache_t::iterator i = m_read_pieces.begin(); + i != m_read_pieces.end();) + { + if (i->storage == j.storage) + { + free_piece(*i, l); + i = m_read_pieces.erase(i); + } + else + { + ++i; + } + } + l.unlock(); + release_memory(); break; } case disk_io_job::abort_thread: diff --git a/src/torrent.cpp b/src/torrent.cpp index 7f15b83c0..b6fe8c252 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2391,11 +2391,14 @@ namespace libtorrent // disconnect all peers and close all // files belonging to the torrents disconnect_all(errors::torrent_aborted); + + // post a message to the main thread to destruct + // the torrent object from there if (m_owning_storage.get()) { - m_storage->async_release_files( - bind(&torrent::on_files_released, shared_from_this(), _1, _2)); m_storage->abort_disk_io(); + m_storage->async_release_files( + boost::bind(&torrent::on_torrent_aborted, shared_from_this(), _1, _2)); } dequeue_torrent_check(); @@ -2503,6 +2506,12 @@ namespace libtorrent */ } + void torrent::on_torrent_aborted(int ret, disk_io_job const& j) + { + // the torrent should be completely shut down now, and the + // destructor has to be called from the main thread + } + void torrent::on_save_resume_data(int ret, disk_io_job const& j) { mutex::scoped_lock l(m_ses.m_mutex);