Skip to content

Commit

Permalink
fix(storage, android): fix an issue that could crash the app when con…
Browse files Browse the repository at this point in the history
…current calls to removeEventListeners were happening (#16996)
  • Loading branch information
Lyokone authored Jan 21, 2025
1 parent b4e46db commit 6499c5f
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,26 @@ private String registerEventChannel(String prefix, String identifier, StreamHand
return identifier;
}

private void removeEventListeners() {
for (String identifier : eventChannels.keySet()) {
eventChannels.get(identifier).setStreamHandler(null);
private synchronized void removeEventListeners() {
// Create a list to hold the keys to remove after iteration
List<String> eventChannelKeys = new ArrayList<>(eventChannels.keySet());
for (String identifier : eventChannelKeys) {
EventChannel eventChannel = eventChannels.get(identifier);
if (eventChannel != null) {
eventChannel.setStreamHandler(null);
}
eventChannels.remove(identifier);
}
eventChannels.clear();

for (String identifier : streamHandlers.keySet()) {
streamHandlers.get(identifier).onCancel(null);
// Create a list to hold the keys to remove after iteration
List<String> streamHandlerKeys = new ArrayList<>(streamHandlers.keySet());
for (String identifier : streamHandlerKeys) {
StreamHandler streamHandler = streamHandlers.get(identifier);
if (streamHandler != null) {
streamHandler.onCancel(null);
}
streamHandlers.remove(identifier);
}
streamHandlers.clear();
}

private FirebaseStorage getStorageFromPigeon(
Expand Down

0 comments on commit 6499c5f

Please sign in to comment.