Browse Source

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>
Daniel Calviño Sánchez 2 năm trước cách đây
mục cha
commit
8364877f38

+ 5 - 1
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -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) {