From 1e20d730730a831fccc5844d57f60231af90e1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 20 Feb 2023 14:50:56 +0100 Subject: [PATCH] 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 Reviewed-by: Konrad Kujawa (cherry picked from commit 32098963f2af064cce42fd5477f2a3137a315aba) Reviewed-by: Qt Cherry-pick Bot --- examples/network/torrent/torrentclient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 5b6edc6dad1..6082e93b014 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -208,6 +208,10 @@ TorrentClient::TorrentClient(QObject *parent) TorrentClient::~TorrentClient() { + auto rateController = RateController::instance(); + const auto childSockets = findChildren(Qt::FindDirectChildrenOnly); + for (PeerWireClient *socket : childSockets) + rateController->removeSocket(socket); qDeleteAll(d->peers); qDeleteAll(d->pendingPieces); delete d;