Skip to content

Commit 12674d2

Browse files
authored
Prevent crash due to race condition when adding magnet link
PR #19792.
1 parent 35e4b35 commit 12674d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/base/bittorrent/sessionimpl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,11 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id)
24032403
return false;
24042404

24052405
const lt::torrent_handle nativeHandle = downloadedMetadataIter.value();
2406+
m_downloadedMetadata.erase(downloadedMetadataIter);
2407+
2408+
if (!nativeHandle.is_valid())
2409+
return true;
2410+
24062411
#ifdef QBT_USES_LIBTORRENT2
24072412
const InfoHash infoHash {nativeHandle.info_hashes()};
24082413
if (infoHash.isHybrid())
@@ -2413,7 +2418,7 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id)
24132418
m_downloadedMetadata.remove((altID == downloadedMetadataIter.key()) ? id : altID);
24142419
}
24152420
#endif
2416-
m_downloadedMetadata.erase(downloadedMetadataIter);
2421+
24172422
m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_files);
24182423
return true;
24192424
}

0 commit comments

Comments
 (0)