浏览代码

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 年之前
父节点
当前提交
8364877f38
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

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