From b2ce9eea831f5343c6a5d4c67a60ac2a1160675c Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Fri, 13 Dec 2024 05:17:07 +0800 Subject: [PATCH] fix: obtain session lock before getting tor ptr (#7286) --- libtransmission/torrent.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 3bccb3e91..8ea4c6acb 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -1603,21 +1603,16 @@ void tr_torrentVerify(tr_torrent* tor) tor->session->run_in_session_thread( [session = tor->session, tor_id = tor->id()]() { + TR_ASSERT(session->am_in_session_thread()); + auto const lock = session->unique_lock(); + auto* const tor = session->torrents().get(tor_id); - if (tor == nullptr) + if (tor == nullptr || tor->is_deleting_) { return; } - TR_ASSERT(tor->session->am_in_session_thread()); - auto const lock = tor->unique_lock(); - - if (tor->is_deleting_) - { - return; - } - - tor->session->verify_remove(tor); + session->verify_remove(tor); if (!tor->has_metainfo()) { @@ -1637,7 +1632,7 @@ void tr_torrentVerify(tr_torrent* tor) tor->start_when_stable_ = false; } - tor->session->verify_add(tor); + session->verify_add(tor); }); }