From 88144bc4b126e41138e1a9c07a194c76eb737e3e Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Mon, 23 Jul 2012 22:14:46 +0200 Subject: [PATCH] Fix another memory leak with linphone_address_as_string_uri_only --- Classes/ChatRoomViewController.m | 16 ++++++++++------ Classes/HistoryDetailsViewController.m | 11 ++++++++--- Classes/HistoryTableViewController.m | 3 ++- Classes/IncomingCallViewController.m | 3 ++- Classes/LinphoneManager.m | 8 +++++++- Classes/LinphoneUI/UICallCell.m | 3 ++- Classes/LinphoneUI/UIHistoryCell.m | 3 ++- Classes/PhoneMainView.m | 3 ++- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index d4d2ab6bc..b1479529e 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -209,12 +209,16 @@ static UICompositeViewDescription *compositeDescription = nil; LinphoneAddress *from = [[[notif userInfo] objectForKey:@"from"] pointerValue]; ChatModel *chat = [[notif userInfo] objectForKey:@"chat"]; if(from != NULL && chat != NULL) { - if([[NSString stringWithUTF8String:linphone_address_as_string_uri_only(from)] - caseInsensitiveCompare:remoteAddress] == NSOrderedSame) { - [chat setRead:[NSNumber numberWithInt:1]]; - [chat update]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"LinphoneTextReceived" object:self]; - [tableController addChatEntry:chat]; + char *fromStr = linphone_address_as_string_uri_only(from); + if(fromStr != NULL) { + if([[NSString stringWithUTF8String:fromStr] + caseInsensitiveCompare:remoteAddress] == NSOrderedSame) { + [chat setRead:[NSNumber numberWithInt:1]]; + [chat update]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"LinphoneTextReceived" object:self]; + [tableController addChatEntry:chat]; + } + ms_free(fromStr); } } else { [LinphoneLogger logc:LinphoneLoggerWarning format:"Invalid textReceivedEvent"]; diff --git a/Classes/HistoryDetailsViewController.m b/Classes/HistoryDetailsViewController.m index be5d45d32..8dc60041e 100644 --- a/Classes/HistoryDetailsViewController.m +++ b/Classes/HistoryDetailsViewController.m @@ -157,7 +157,7 @@ static UICompositeViewDescription *compositeDescription = nil; if(addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; @@ -166,6 +166,7 @@ static UICompositeViewDescription *compositeDescription = nil; address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); @@ -234,10 +235,11 @@ static UICompositeViewDescription *compositeDescription = nil; if (addr != NULL) { // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress != NULL) { [addressButton setTitle:[NSString stringWithUTF8String:lAddress] forState:UIControlStateNormal]; [addressButton setHidden:FALSE]; + ms_free(lAddress); } else { [addressButton setHidden:TRUE]; } @@ -280,7 +282,9 @@ static UICompositeViewDescription *compositeDescription = nil; addr = callLog->to; } - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); + if(lAddress == NULL) + return; NSString *displayName = nil; if(contact != nil) { @@ -303,6 +307,7 @@ static UICompositeViewDescription *compositeDescription = nil; [controller call:[NSString stringWithUTF8String:lAddress]]; } } + ms_free(lAddress); } @end diff --git a/Classes/HistoryTableViewController.m b/Classes/HistoryTableViewController.m index 28d85ccc2..ad0c33234 100644 --- a/Classes/HistoryTableViewController.m +++ b/Classes/HistoryTableViewController.m @@ -137,7 +137,7 @@ if(addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { address = [NSString stringWithUTF8String:lAddress]; NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:address]; @@ -146,6 +146,7 @@ displayName = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); diff --git a/Classes/IncomingCallViewController.m b/Classes/IncomingCallViewController.m index 251a94f84..7553a0fbe 100644 --- a/Classes/IncomingCallViewController.m +++ b/Classes/IncomingCallViewController.m @@ -97,7 +97,7 @@ if (addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; @@ -106,6 +106,7 @@ address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 202183dcb..1cce9fbc8 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -330,15 +330,21 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo - (void)onTextReceived:(LinphoneCore *)lc room:(LinphoneChatRoom *)room from:(const LinphoneAddress *)from message:(const char *)message { + char *fromStr = linphone_address_as_string_uri_only(from); + if(fromStr == NULL) + return; + // Save message in database ChatModel *chat = [[ChatModel alloc] init]; - [chat setRemoteContact:[NSString stringWithUTF8String:linphone_address_as_string_uri_only(from)]]; + [chat setRemoteContact:[NSString stringWithUTF8String:fromStr]]; [chat setMessage:[NSString stringWithUTF8String:message]]; [chat setDirection:[NSNumber numberWithInt:1]]; [chat setTime:[NSDate date]]; [chat setRead:[NSNumber numberWithInt:0]]; [chat create]; + ms_free(fromStr); + // Post event NSDictionary* dict = [[[NSDictionary alloc] initWithObjectsAndKeys: [NSValue valueWithPointer:room], @"room", diff --git a/Classes/LinphoneUI/UICallCell.m b/Classes/LinphoneUI/UICallCell.m index ea2b481a3..0c863581b 100644 --- a/Classes/LinphoneUI/UICallCell.m +++ b/Classes/LinphoneUI/UICallCell.m @@ -171,7 +171,7 @@ if(addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; @@ -180,6 +180,7 @@ address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index 0c95d3f48..8b2730618 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -118,7 +118,7 @@ if(addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; @@ -126,6 +126,7 @@ address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index cf89a8ac8..bb467a11a 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -483,7 +483,7 @@ static PhoneMainView* phoneMainViewInstance=nil; if(addr != NULL) { BOOL useLinphoneAddress = true; // contact name - const char* lAddress = linphone_address_as_string_uri_only(addr); + char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; @@ -491,6 +491,7 @@ static PhoneMainView* phoneMainViewInstance=nil; address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } + ms_free(lAddress); } if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr);