From 7183116b4b1f07bdb3650602b7dcb2cb14ab4ba7 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Thu, 6 May 2021 17:35:45 +0200 Subject: [PATCH] fix leak memory --- Classes/ChatConversationCreateTableView.m | 4 +++- Classes/ChatConversationInfoView.m | 12 +++++++++--- Classes/ChatConversationView.m | 4 +++- Classes/LinphoneCoreSettingsStore.m | 5 +++-- Classes/LinphoneUI/UIDeviceCell.m | 4 +++- Classes/SideMenuView.m | 4 +++- Classes/Utils/FastAddressBook.m | 10 +++++++--- Classes/Utils/Utils.m | 9 ++++++--- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 54b9ef55d..4eee3d8c3 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -174,7 +174,9 @@ BOOL greyCellForGroupChat = _isGroupChat ? capabilities > 0 : TRUE; cell.userInteractionEnabled = cell.greyView.hidden = greyCellForEncryptedChat && greyCellForGroupChat; cell.displayNameLabel.text = [FastAddressBook displayNameForAddress:addr]; - cell.addressLabel.text = linphoneContact ? [NSString stringWithUTF8String:linphone_address_as_string(addr)] : phoneOrAddr; + char *str = linphone_address_as_string(addr); + cell.addressLabel.text = linphoneContact ? [NSString stringWithUTF8String:str] : phoneOrAddr; + ms_free(str); cell.selectedImage.hidden = ![_contactsGroup containsObject:cell.addressLabel.text]; [cell.avatarImage setImage:[FastAddressBook imageForAddress:addr] bordered:NO withRoundedRadius:YES]; cell.contentView.userInteractionEnabled = false; diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index 67defd595..c277bac97 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -362,7 +362,9 @@ void chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog *eve void chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); - NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; + char *str = linphone_address_as_string(linphone_event_log_get_participant_address(event_log)); + NSString *participantAddress = [NSString stringWithUTF8String:str]; + ms_free(str); [view.oldContacts addObject:participantAddress]; [view.contacts addObject:participantAddress]; [view.tableView reloadData]; @@ -370,7 +372,9 @@ void chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *e void chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); - NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; + char *str = linphone_address_as_string(linphone_event_log_get_participant_address(event_log)); + NSString *participantAddress = [NSString stringWithUTF8String:str]; + ms_free(str); [view.oldContacts removeObject:participantAddress]; [view.contacts removeObject:participantAddress]; [view.tableView reloadData]; @@ -378,7 +382,9 @@ void chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog void chat_room_participant_admin_status_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); - NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; + char *str = linphone_address_as_string(linphone_event_log_get_participant_address(event_log)); + NSString *participantAddress = [NSString stringWithUTF8String:str]; + ms_free(str); LinphoneParticipant *me = linphone_chat_room_get_me(cr); if (me && linphone_address_equal(linphone_participant_get_address(me), linphone_event_log_get_participant_address(event_log))) { diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 8c3b5a1d3..43ac5f8a3 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -766,12 +766,14 @@ static UICompositeViewDescription *compositeDescription = nil; bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom); while (participants) { LinphoneParticipant *participant = (LinphoneParticipant *)participants->data; - NSString *uri = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_participant_get_address(participant))]; + char *curi = linphone_address_as_string_uri_only(linphone_participant_get_address(participant)); + NSString *uri = [NSString stringWithUTF8String:curi]; [contactsArray addObject:uri]; if(linphone_participant_is_admin(participant)) [admins addObject:uri]; participants = participants->next; + ms_free(curi); } ChatConversationInfoView *view = VIEW(ChatConversationInfoView); view.create = FALSE; diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 286f55e2a..b7676b07f 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -548,7 +548,6 @@ } linphone_address_set_domain(linphoneAddress, [domain UTF8String]); linphone_address_set_display_name(linphoneAddress, (displayName.length ? displayName.UTF8String : NULL)); - const char *identity = linphone_address_as_string(linphoneAddress); const char *password = [accountPassword UTF8String]; const char *ha1 = [accountHa1 UTF8String]; @@ -613,8 +612,10 @@ if (strcmp(password,"") == 0) { password = NULL; } - + + char *identity = linphone_address_as_string(linphoneAddress); LinphoneAddress *from = linphone_core_interpret_url(LC, identity); + ms_free(identity); if (from) { const char *userid_str = (userID != nil) ? [userID UTF8String] : NULL; LinphoneAuthInfo *info; diff --git a/Classes/LinphoneUI/UIDeviceCell.m b/Classes/LinphoneUI/UIDeviceCell.m index cb40d54ac..1639cd530 100644 --- a/Classes/LinphoneUI/UIDeviceCell.m +++ b/Classes/LinphoneUI/UIDeviceCell.m @@ -42,8 +42,10 @@ } [_securityButton setImage:[FastAddressBook imageForSecurityLevel:linphone_participant_device_get_security_level(_device)] forState:UIControlStateNormal]; + char *uri = linphone_address_as_string_uri_only(linphone_participant_device_get_address(_device)); _deviceLabel.text = [NSString stringWithUTF8String:linphone_participant_device_get_name(_device) ? : - linphone_address_as_string_uri_only(linphone_participant_device_get_address(_device))]; + uri]; + ms_free(uri); if (_isOneToOne) { CGRect frame =_deviceLabel.frame; frame.origin.x = 30; diff --git a/Classes/SideMenuView.m b/Classes/SideMenuView.m index c4c5de353..9fb1aaded 100644 --- a/Classes/SideMenuView.m +++ b/Classes/SideMenuView.m @@ -66,7 +66,9 @@ if (default_proxy != NULL) { const LinphoneAddress *addr = linphone_proxy_config_get_identity_address(default_proxy); [ContactDisplay setDisplayNameLabel:_nameLabel forAddress:addr]; - _addressLabel.text = addr? [NSString stringWithUTF8String:linphone_address_as_string(addr)] : NSLocalizedString(@"No address", nil); + char *str = addr ? linphone_address_as_string(addr) : nil; + _addressLabel.text = str ? [NSString stringWithUTF8String:str] : NSLocalizedString(@"No address", nil); + if (str) ms_free(str); _presenceImage.image = [StatusBarView imageForState:linphone_proxy_config_get_state(default_proxy)]; } else { _nameLabel.text = linphone_core_get_proxy_config_list(LC) ? NSLocalizedString(@"No default account", nil) : NSLocalizedString(@"No account", nil); diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index d9a73a4a9..cfdd3a832 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -90,8 +90,9 @@ if (cfg) { const char *normvalue = linphone_proxy_config_normalize_phone_number(cfg, phone.UTF8String); LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, normvalue); - const char *phone_addr = linphone_address_as_string_uri_only(addr); + char *phone_addr = linphone_address_as_string_uri_only(addr); contact = [FastAddressBook getContact:[NSString stringWithUTF8String:phone_addr]]; + ms_free(phone_addr); } else { contact = [FastAddressBook getContact:phone]; } @@ -602,10 +603,13 @@ if (displayName == nil) return; const LinphonePresenceModel *m = [[k.userInfo valueForKey:@"presence_model"] pointerValue]; - if (!linphone_presence_model_get_contact(m)) { + char *str = linphone_presence_model_get_contact(m); + if (str == nil) { return; } - NSString *contact = [NSString stringWithUTF8String:linphone_presence_model_get_contact(m)]; + + NSString *contact = [NSString stringWithUTF8String:str]; + ms_free(str); NSString *sipAddr = [FastAddressBook normalizeSipURI:contact]; if (sipAddr != nil && [displayNames objectForKey:sipAddr] == nil) { diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 054786af8..0fc436eac 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -472,9 +472,10 @@ const LinphonePresenceModel *m = f ? linphone_friend_get_presence_model_for_uri_or_tel(f, value.UTF8String) : NULL; - const char *contact = m ? linphone_presence_model_get_contact(m) : NULL; + char *contact = m ? linphone_presence_model_get_contact(m) : NULL; if (contact) { LinphoneAddress *contact_addr = linphone_address_new(contact); + ms_free(contact); if (contact_addr) { linphone_address_unref(addr); return contact_addr; @@ -617,17 +618,19 @@ + (void)setDisplayNameLabel:(UILabel *)label forAddress:(const LinphoneAddress *)addr withAddressLabel:(UILabel*)addressLabel{ Contact *contact = [FastAddressBook getContactWithAddress:addr]; NSString *tmpAddress = nil; + char *uri = linphone_address_as_string_uri_only(addr); if (contact) { [ContactDisplay setDisplayNameLabel:label forContact:contact]; - tmpAddress = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(addr)]; + tmpAddress = [NSString stringWithUTF8String:uri]; addressLabel.hidden = FALSE; } else { label.text = [FastAddressBook displayNameForAddress:addr]; if([LinphoneManager.instance lpConfigBoolForKey:@"display_phone_only" inSection:@"app"]) addressLabel.hidden = TRUE; else - tmpAddress = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(addr)]; + tmpAddress = [NSString stringWithUTF8String:uri]; } + ms_free(uri); NSRange range = [tmpAddress rangeOfString:@";"]; if (range.location != NSNotFound) { tmpAddress = [tmpAddress substringToIndex:range.location];