Fix crash after hangup due to modifying a list while iterating over it

"endPeerConnection()" removes the item from the list, so neither a
for-each loop nor an iterator can be used to traverse the list (as a
"ConcurrentModificationException" would be thrown). To solve that now
the list of connections is first traversed to get all the sessions, and
then the list of sessions is traversed to end the connections.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2022-09-19 01:49:33 +02:00 committed by Tim Krüger
parent 53e3543839
commit 8364877f38
No known key found for this signature in database
GPG key ID: FECE3A7222C52A4E

View file

@ -1707,8 +1707,12 @@ public class CallActivity extends CallBaseActivity {
}
}
List<String> sessionIdsToEnd = new ArrayList<String>(peerConnectionWrapperList.size());
for (PeerConnectionWrapper wrapper : peerConnectionWrapperList) {
endPeerConnection(wrapper.getSessionId(), false);
sessionIdsToEnd.add(wrapper.getSessionId());
}
for (String sessionId : sessionIdsToEnd) {
endPeerConnection(sessionId, false);
}
if (localStream != null) {