From fe56c6d9469ebd7d30c13b6313b7ce35dad94941 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 6 Jun 2022 17:14:06 +0200 Subject: [PATCH] Fix crash that would occur when typing too fast in the chatroom creation search bar (race condition), and fix possible infinite loop when having some specific conditions in the phone contacts --- Classes/ChatConversationCreateTableView.m | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index efc6a2bd5..9a512a997 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -98,13 +98,13 @@ } - (void) buildChatContactTable { - [_ldapContactAddressBookMap removeAllObjects]; + bctbx_list_t *results = [MagicSearchSingleton.instance getLastSearchResults]; while (results) { LinphoneSearchResult *result = results->data; const LinphoneAddress *addr = linphone_search_result_get_address(result); - + const char *phoneNumber = NULL; Contact *contact = nil; char *uri = nil; @@ -119,6 +119,7 @@ if (!addr || (!contact && friend)) { phoneNumber = linphone_search_result_get_phone_number(result); if (!phoneNumber) { + results = results->next; continue; } @@ -127,6 +128,7 @@ const char *normalizedPhoneNumber = linphone_account_normalize_phone_number(account, phoneNumber); if (!normalizedPhoneNumber) { // get invalid phone number, continue + results = results->next; continue; } addr = linphone_account_normalize_sip_uri(account, normalizedPhoneNumber); @@ -139,12 +141,12 @@ } } - + if (!addr) { results = results->next; continue; } - + ms_free(uri); [_addresses addObject:address]; @@ -153,10 +155,11 @@ results = results->next; } - _reloadMagicSearch = FALSE; [self.tableView reloadData]; + _reloadMagicSearch = FALSE; } + - (void) loadData { [self reloadDataWithFilter:_searchBar.text]; } @@ -165,6 +168,9 @@ [_addresses removeAllObjects]; [_phoneOrAddr removeAllObjects]; [_addressesCached removeAllObjects]; + [_ldapContactAddressBookMap removeAllObjects]; + [self.tableView reloadData]; + _reloadMagicSearch = _reloadMagicSearch || [filter length]==0 || ![[MagicSearchSingleton.instance currentFilter] isEqualToString:filter]; [MagicSearchSingleton.instance setCurrentFilter:filter];