summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2023-02-20 14:50:56 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-21 12:05:10 +0000
commit1e20d730730a831fccc5844d57f60231af90e1c1 (patch)
tree1ee85a88847e0f935527969f8a15aec7d19941aa /examples
parent44eabe2f936c25c8746c3818e165224e0e00178e (diff)
downloadqtbase-1e20d730730a831fccc5844d57f60231af90e1c1.tar.gz
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>
Diffstat (limited to 'examples')
-rw-r--r--examples/network/torrent/torrentclient.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index 5b6edc6dad..6082e93b01 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<PeerWireClient *>(Qt::FindDirectChildrenOnly);
+ for (PeerWireClient *socket : childSockets)
+ rateController->removeSocket(socket);
qDeleteAll(d->peers);
qDeleteAll(d->pendingPieces);
delete d;