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>
This commit is contained in:
parent
30be6c41d5
commit
1018dba04f
@ -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());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user