avoid array mutated while being enumerated

This commit is contained in:
Danmei Chen 2021-03-29 14:44:20 +02:00
parent 01bb34843d
commit 03ee02ded8
3 changed files with 10 additions and 2 deletions

View file

@ -1387,7 +1387,8 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat
// rare case, remove duplicated fileTransferDelegates to avoid crash // rare case, remove duplicated fileTransferDelegates to avoid crash
[_fileTransferDelegates setArray:[[NSSet setWithArray:_fileTransferDelegates] allObjects]]; [_fileTransferDelegates setArray:[[NSSet setWithArray:_fileTransferDelegates] allObjects]];
for (FileTransferDelegate *ftd in _fileTransferDelegates) { for (FileTransferDelegate *ftd in _fileTransferDelegates) {
[ftd stopAndDestroy]; // Not remove here, avoid array mutated while being enumerated
[ftd stopAndDestroyAndRemove:FALSE];
} }
[_fileTransferDelegates removeAllObjects]; [_fileTransferDelegates removeAllObjects];

View file

@ -30,6 +30,7 @@
- (void)cancel; - (void)cancel;
- (BOOL)download:(LinphoneChatMessage *)message; - (BOOL)download:(LinphoneChatMessage *)message;
- (void)stopAndDestroy; - (void)stopAndDestroy;
- (void)stopAndDestroyAndRemove:(BOOL)remove;
+ (FileTransferDelegate *)messageDelegate:(LinphoneChatMessage *)message; + (FileTransferDelegate *)messageDelegate:(LinphoneChatMessage *)message;
@property() LinphoneChatMessage *message; @property() LinphoneChatMessage *message;

View file

@ -173,7 +173,13 @@ static void file_transfer_progress_indication_send(LinphoneChatMessage *message,
} }
- (void)stopAndDestroy { - (void)stopAndDestroy {
[[LinphoneManager.instance fileTransferDelegates] removeObject:self]; [self stopAndDestroyAndRemove:TRUE];
}
- (void)stopAndDestroyAndRemove:(BOOL)remove {
if (remove)
[[LinphoneManager.instance fileTransferDelegates] removeObject:self];
if (_message != NULL) { if (_message != NULL) {
LinphoneChatMessage *msg = _message; LinphoneChatMessage *msg = _message;
_message = NULL; _message = NULL;