Torrent example: Fix use-after-free crash

The crash would sometimes happen shortly after removing a torrent
since the RateController would still try to use it even though
it had been deallocated.

Task-number: QTBUG-110622
Change-Id: Icad1531ea58560a3a3157a3ed8c0e6b283573196
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
(cherry picked from commit 32098963f2af064cce42fd5477f2a3137a315aba)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2023-02-20 14:50:56 +01:00 committed by Qt Cherry-pick Bot
parent 44eabe2f93
commit 1e20d73073

View File

@ -208,6 +208,10 @@ TorrentClient::TorrentClient(QObject *parent)
TorrentClient::~TorrentClient()
{
auto rateController = RateController::instance();
const auto childSockets = findChildren<PeerWireClient *>(Qt::FindDirectChildrenOnly);
for (PeerWireClient *socket : childSockets)
rateController->removeSocket(socket);
qDeleteAll(d->peers);
qDeleteAll(d->pendingPieces);
delete d;