From 8364877f385d95e45004d2af4fed0dddadce2f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 19 Sep 2022 01:49:33 +0200 Subject: [PATCH] Fix crash after hangup due to modifying a list while iterating over it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "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 --- .../java/com/nextcloud/talk/activities/CallActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 0f691f353..c1fa047fa 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1707,8 +1707,12 @@ public class CallActivity extends CallBaseActivity { } } + List sessionIdsToEnd = new ArrayList(peerConnectionWrapperList.size()); for (PeerConnectionWrapper wrapper : peerConnectionWrapperList) { - endPeerConnection(wrapper.getSessionId(), false); + sessionIdsToEnd.add(wrapper.getSessionId()); + } + for (String sessionId : sessionIdsToEnd) { + endPeerConnection(sessionId, false); } if (localStream != null) {