diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-05-05 16:49:03 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-05-11 10:21:29 +0200 |
commit | 1018dba04ff6b2f018cbd1a22ae630daa473bfb4 (patch) | |
tree | 84c150e52a318572f7389a9e52c6824e467bb762 /examples/network/torrent/ratecontroller.cpp | |
parent | 30be6c41d5bb8ff4f42dd7ac26a763444be71c5a (diff) |
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 <marc.mutz@kdab.com>
Diffstat (limited to 'examples/network/torrent/ratecontroller.cpp')
-rw-r--r-- | examples/network/torrent/ratecontroller.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
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()); |