From 1018dba04ff6b2f018cbd1a22ae630daa473bfb4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 5 May 2020 16:49:03 +0200 Subject: Torrent example: fix crash Yet Another Side Effect of not keeping iterator stability. Although not idiomatic, the pattern while (i != e) { auto cur = i++; if (cond) erase(cur); } was actually correct. Move to the idiomatic erase pattern instead (it = cont.erase(it)). The example still has memory problems all over the place on shutdown. At least now it doesn't crash when running. Change-Id: I30bd2c4e2b3fa7fe4e28d4426ff3d894b9bae103 Reviewed-by: Marc Mutz --- examples/network/torrent/ratecontroller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/network') diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp index 756947b65c..18d0737dbb 100644 --- a/examples/network/torrent/ratecontroller.cpp +++ b/examples/network/torrent/ratecontroller.cpp @@ -129,7 +129,7 @@ void RateController::transfer() auto current = it++; PeerWireClient *socket = *current; if (socket->state() != QAbstractSocket::ConnectedState) { - pendingSockets.erase(current); + it = pendingSockets.erase(current); continue; } @@ -158,7 +158,7 @@ void RateController::transfer() if (dataTransferred && socket->canTransferMore()) canTransferMore = true; else - pendingSockets.erase(current); + it = pendingSockets.erase(current); } } while (canTransferMore && (bytesToWrite > 0 || bytesToRead > 0) && !pendingSockets.isEmpty()); -- cgit v1.2.3