From 4325741e61192c387b0d1602494ad934675e8fd2 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 6 Jan 2012 10:43:23 +0100 Subject: [PATCH] Fix objC memory leaks --- Classes/CallHistoryTableViewController.m | 27 ++++++++++++++--------- Classes/ConferenceCallDetailView.m | 1 + Classes/ConsoleViewController.m | 4 ++-- Classes/ContactPickerDelegate.m | 4 +++- Classes/FirstLoginViewController.m | 2 ++ Classes/IncallViewController.m | 16 +++++++------- Classes/LinphoneAppDelegate.m | 3 +++ Classes/LinphoneUI/FastAddressBook.m | 1 + Classes/LinphoneUI/LinphoneManager.m | 28 +++++++++++++++++------- Classes/LinphoneUI/UICallButton.h | 1 - Classes/LinphoneUI/UICallButton.m | 3 ++- Classes/LinphoneUI/UIToggleButton.h | 1 - Classes/PhoneViewController.m | 3 ++- 13 files changed, 61 insertions(+), 33 deletions(-) diff --git a/Classes/CallHistoryTableViewController.m b/Classes/CallHistoryTableViewController.m index ab7dc6a83..13d07f9c3 100644 --- a/Classes/CallHistoryTableViewController.m +++ b/Classes/CallHistoryTableViewController.m @@ -43,6 +43,7 @@ target:self action:@selector(doAction:)]; [self.navigationItem setRightBarButtonItem:clearButton]; + [clearButton release]; } /* @@ -144,15 +145,21 @@ const char* username = linphone_address_get_username(partyToDisplay)!=0?linphone_address_get_username(partyToDisplay):""; const char* displayName = linphone_address_get_display_name(partyToDisplay); + // explicit release are needed to avoid mem leaks : NSString are created with retainCount == 1. + // Assigning them to a textLabel.text property (which has 'retain' flag) bumps it to 2. So we set them back to 1. if (displayName) { - [cell.textLabel setText:[[NSString alloc] initWithCString:displayName encoding:[NSString defaultCStringEncoding]]]; - [cell.detailTextLabel setText:[NSString stringWithFormat:@"%s"/* [%s]"*/,username/*,callLogs->start_date*/]]; - } else { - [cell.textLabel setText:[[NSString alloc] initWithCString:username encoding:[NSString defaultCStringEncoding]]]; - [cell.detailTextLabel setText:nil]; - } - - + NSString* str1 = [[NSString alloc] initWithCString:displayName encoding:[NSString defaultCStringEncoding]]; + [cell.textLabel setText:str1]; + NSString* str2 = [NSString stringWithFormat:@"%s"/* [%s]"*/,username/*,callLogs->start_date*/]; + [cell.detailTextLabel setText:str2]; + [str1 release]; + assert(str1.retainCount == 1); + } else { + NSString* str1 = [[NSString alloc] initWithCString:username encoding:[NSString defaultCStringEncoding]]; + [cell.textLabel setText:str1]; + [cell.detailTextLabel setText:nil]; + [str1 release]; + } return cell; } @@ -191,8 +198,8 @@ } [[LinphoneManager instance].callDelegate displayDialerFromUI:self forUser:phoneNumber - withDisplayName:[[NSString alloc] initWithCString:displayName encoding:[NSString defaultCStringEncoding]]]; - + withDisplayName:[[[NSString alloc] initWithCString:displayName encoding:[NSString defaultCStringEncoding]] autorelease]]; + [phoneNumber release]; } diff --git a/Classes/ConferenceCallDetailView.m b/Classes/ConferenceCallDetailView.m index 7eceffcc8..a8f47c07b 100644 --- a/Classes/ConferenceCallDetailView.m +++ b/Classes/ConferenceCallDetailView.m @@ -156,6 +156,7 @@ NSTimer *callQualityRefresher; [cell.accessoryView addSubview:callquality]; tableView.rowHeight = 80;//cell.bounds.size.height; + [callquality release]; return cell; } diff --git a/Classes/ConsoleViewController.m b/Classes/ConsoleViewController.m index 36a01a466..c2ee28379 100644 --- a/Classes/ConsoleViewController.m +++ b/Classes/ConsoleViewController.m @@ -41,10 +41,10 @@ NSMutableString* MoreViewController_logs; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; - UIBarButtonItem* clear = [[UIBarButtonItem alloc] + UIBarButtonItem* clear = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self - action:@selector(doAction)]; + action:@selector(doAction)] autorelease]; [self.navigationItem setRightBarButtonItem:clear]; } diff --git a/Classes/ContactPickerDelegate.m b/Classes/ContactPickerDelegate.m index 62f429dfa..00d53e489 100644 --- a/Classes/ContactPickerDelegate.m +++ b/Classes/ContactPickerDelegate.m @@ -38,7 +38,9 @@ NSString *phoneNumber = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, valueIdx); [[LinphoneManager instance].callDelegate displayDialerFromUI:nil forUser:phoneNumber - withDisplayName:(NSString*)ABRecordCopyCompositeName(person)]; + withDisplayName:[(NSString*)ABRecordCopyCompositeName(person) autorelease]]; + [phoneNumber release]; + CFRelease(multiValue); return false; } diff --git a/Classes/FirstLoginViewController.m b/Classes/FirstLoginViewController.m index 335604561..99bd808c5 100644 --- a/Classes/FirstLoginViewController.m +++ b/Classes/FirstLoginViewController.m @@ -77,6 +77,7 @@ cancelButtonTitle:NSLocalizedString(@"Continue",nil) otherButtonTitles:nil]; [error show]; + [error release]; } else { [[NSUserDefaults standardUserDefaults] setObject:username.text forKey:@"username_preference"]; [[NSUserDefaults standardUserDefaults] setObject:passwd.text forKey:@"password_preference"]; @@ -104,6 +105,7 @@ cancelButtonTitle:@"Continue" otherButtonTitles:nil ,nil]; [error show]; + [error release]; //erase uername passwd [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"username_preference"]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"password_preference"]; diff --git a/Classes/IncallViewController.m b/Classes/IncallViewController.m index 9fa171804..cc62ef1f0 100644 --- a/Classes/IncallViewController.m +++ b/Classes/IncallViewController.m @@ -63,23 +63,23 @@ const NSInteger SECURE_BUTTON_TAG=5; + (UIImage*) stat_sys_signal_0 { - return [[UIImage imageNamed:@"stat_sys_signal_0.png"] retain]; + return [UIImage imageNamed:@"stat_sys_signal_0.png"]; } + (UIImage*) stat_sys_signal_1 { - return [[UIImage imageNamed:@"stat_sys_signal_1.png"] retain]; + return [UIImage imageNamed:@"stat_sys_signal_1.png"]; } + (UIImage*) stat_sys_signal_2 { - return [[UIImage imageNamed:@"stat_sys_signal_2.png"] retain]; + return [UIImage imageNamed:@"stat_sys_signal_2.png"]; } + (UIImage*) stat_sys_signal_3 { - return [[UIImage imageNamed:@"stat_sys_signal_3.png"] retain]; + return [UIImage imageNamed:@"stat_sys_signal_3.png"]; } + (UIImage*) stat_sys_signal_4 { - return [[UIImage imageNamed:@"stat_sys_signal_4.png"] retain];; + return [UIImage imageNamed:@"stat_sys_signal_4.png"]; } bool isInConference(LinphoneCall* call) { @@ -393,7 +393,7 @@ int callCount(LinphoneCore* lc) { } else if (sender == contacts) { // start people picker myPeoplePickerController = [[[ABPeoplePickerNavigationController alloc] init] autorelease]; - [myPeoplePickerController setPeoplePickerDelegate:[[ContactPickerDelegate alloc] init] /*self*/]; + [myPeoplePickerController setPeoplePickerDelegate:[[[ContactPickerDelegate alloc] init] autorelease]]; [self presentModalViewController: myPeoplePickerController animated:true]; } else if (sender == close) { @@ -494,7 +494,7 @@ int callCount(LinphoneCore* lc) { if (addr) { const char* lUserNameChars=linphone_address_get_username(addr); - NSString* lUserName = lUserNameChars?[[NSString alloc] initWithUTF8String:lUserNameChars]:NSLocalizedString(@"Unknown",nil); + NSString* lUserName = lUserNameChars?[[[NSString alloc] initWithUTF8String:lUserNameChars] autorelease]:NSLocalizedString(@"Unknown",nil); NSMutableString* mss = [[NSMutableString alloc] init]; /* contact name */ const char* n = linphone_address_get_display_name(addr); @@ -509,7 +509,6 @@ int callCount(LinphoneCore* lc) { imageView.image = [[LinphoneManager instance] getImageFromAddressBook:lUserName]; } [mss release]; - [lUserName release]; } else { [label setText:@"plop"]; imageView.image = nil; @@ -673,6 +672,7 @@ int callCount(LinphoneCore* lc) { } [cell.accessoryView addSubview:callquality]; + [callquality release]; } cell.userInteractionEnabled = YES; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index dcb97b6b7..2a813d0f5 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -112,6 +112,7 @@ //more tab MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:[NSBundle mainBundle]]; UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:moreViewController]; + [moreViewController release]; //copy tab bar item aNavigationController.tabBarItem = [(UIViewController*)[myTabBarController.viewControllers objectAtIndex:MORE_TAB_INDEX] tabBarItem]; @@ -119,7 +120,9 @@ NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.myTabBarController.viewControllers]; [newArray replaceObjectAtIndex:CONTACTS_TAB_INDEX withObject:myPeoplePickerController]; [newArray replaceObjectAtIndex:MORE_TAB_INDEX withObject:aNavigationController]; + [aNavigationController release]; [newArray replaceObjectAtIndex:HISTORY_TAB_INDEX withObject:aCallHistNavigationController]; + [aCallHistNavigationController release]; [myTabBarController setSelectedIndex:DIALER_TAB_INDEX]; [myTabBarController setViewControllers:newArray animated:NO]; diff --git a/Classes/LinphoneUI/FastAddressBook.m b/Classes/LinphoneUI/FastAddressBook.m index c08762045..1f88a0077 100644 --- a/Classes/LinphoneUI/FastAddressBook.m +++ b/Classes/LinphoneUI/FastAddressBook.m @@ -62,6 +62,7 @@ void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void Contact* lContact = [[Contact alloc] initWithRecord:lPerson ofType:(NSString *)lLocalizedLabel]; [lAddressBookMap setObject:lContact forKey:lNormalizedKey]; CFRelease(lValue); + [lContact release]; if (lLabel) CFRelease(lLabel); if (lLocalizedLabel) CFRelease(lLocalizedLabel); } diff --git a/Classes/LinphoneUI/LinphoneManager.m b/Classes/LinphoneUI/LinphoneManager.m index b2be5fad7..4fad424d5 100644 --- a/Classes/LinphoneUI/LinphoneManager.m +++ b/Classes/LinphoneUI/LinphoneManager.m @@ -92,7 +92,7 @@ extern void libmssilk_init(); linphone_call_log_set_ref_key(log, ltmpString); CFRelease(lFormatedString); } - return (NSString*)lDisplayName; + return [(NSString*)lDisplayName autorelease]; } //[number release]; @@ -112,7 +112,7 @@ extern void libmssilk_init(); } else { d = (NSData*)ABPersonCopyImageData(person); } - return [UIImage imageWithData:d]; + return [UIImage imageWithData:[d autorelease]]; } } /* return default image */ @@ -143,16 +143,18 @@ extern void libmssilk_init(); } else { ms_message("No contact entry found for [%s] in address book",lUserName); } + + [lE164Number release]; return; } -(void) onCall:(LinphoneCall*) call StateChanged: (LinphoneCallState) new_state withMessage: (const char *) message { const char* lUserNameChars=linphone_address_get_username(linphone_call_get_remote_address(call)); - NSString* lUserName = lUserNameChars?[[NSString alloc] initWithUTF8String:lUserNameChars]:NSLocalizedString(@"Unknown",nil); + NSString* lUserName = lUserNameChars?[[[NSString alloc] initWithUTF8String:lUserNameChars] autorelease]:NSLocalizedString(@"Unknown",nil); if (new_state == LinphoneCallIncomingReceived) { [self updateCallWithAddressBookData:call]; // display name is updated } const char* lDisplayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(call)); - NSString* lDisplayName = lDisplayNameChars?[[NSString alloc] initWithUTF8String:lDisplayNameChars]:@""; + NSString* lDisplayName = [lDisplayNameChars?[[NSString alloc] initWithUTF8String:lDisplayNameChars]:@"" autorelease]; bool canHideInCallView = (linphone_core_get_calls([LinphoneManager getLc]) == NULL); @@ -216,6 +218,7 @@ extern void libmssilk_init(); cancelButtonTitle:NSLocalizedString(@"Dismiss",nil) otherButtonTitles:nil]; [error show]; + [error release]; if (canHideInCallView) { [callDelegate displayDialerFromUI:mCurrentViewController forUser:@"" @@ -277,7 +280,9 @@ static void linphone_iphone_log(struct _LinphoneCore * lc, const char * message) } //status static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char * message) { - [(LinphoneManager*)linphone_core_get_user_data(lc) displayStatus:[[NSString alloc] initWithCString:message encoding:[NSString defaultCStringEncoding]]]; + NSString* status = [[NSString alloc] initWithCString:message encoding:[NSString defaultCStringEncoding]]; + [(LinphoneManager*)linphone_core_get_user_data(lc) displayStatus:status]; + [status release]; } static void linphone_iphone_call_state(LinphoneCore *lc, LinphoneCall* call, LinphoneCallState state,const char* message) { @@ -350,6 +355,10 @@ static void linphone_iphone_call_state(LinphoneCore *lc, LinphoneCall* call, Lin } } + + [lUserName release]; + [lDisplayName release]; + [lDomain release]; } static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyConfig* cfg, LinphoneRegistrationState state,const char* message) { @@ -491,8 +500,6 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach //clear existing proxy config linphone_core_clear_proxy_config(theLinphoneCore); if (username && [username length] >0 && domain && [domain length]>0) { - - const char* identity = [[NSString stringWithFormat:@"sip:%@@%@",username,domain] cStringUsingEncoding:[NSString defaultCStringEncoding]]; const char* password = [accountPassword cStringUsingEncoding:[NSString defaultCStringEncoding]]; @@ -546,6 +553,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach cancelButtonTitle:NSLocalizedString(@"Continue",nil) otherButtonTitles:NSLocalizedString(@"Never remind",nil),nil]; [error show]; + [error release]; } } @@ -620,7 +628,10 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach NSString *platform = [[NSString alloc ] initWithUTF8String:machine]; free(machine); - return ![platform isEqualToString:@"iPhone1,2"]; + BOOL result = ![platform isEqualToString:@"iPhone1,2"]; + + [platform release]; + return result; } // no proxy configured alert @@ -789,6 +800,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach cancelButtonTitle:NSLocalizedString(@"Ok",nil) otherButtonTitles:nil ,nil]; [error show]; + [error release]; } /*DETECT cameras*/ frontCamId= backCamId=nil; diff --git a/Classes/LinphoneUI/UICallButton.h b/Classes/LinphoneUI/UICallButton.h index 08301ae5c..f5dc0db54 100644 --- a/Classes/LinphoneUI/UICallButton.h +++ b/Classes/LinphoneUI/UICallButton.h @@ -22,7 +22,6 @@ @interface UICallButton : UIButton { @private - char mDigit; UITextField* mAddress; } -(void) initWithAddress:(UITextField*) address; diff --git a/Classes/LinphoneUI/UICallButton.m b/Classes/LinphoneUI/UICallButton.m index 7846548d8..58ddac124 100644 --- a/Classes/LinphoneUI/UICallButton.m +++ b/Classes/LinphoneUI/UICallButton.m @@ -30,6 +30,7 @@ cancelButtonTitle:NSLocalizedString(@"Continue",nil) otherButtonTitles:nil]; [error show]; + [error release]; return; } if (TRUE /*!linphone_core_in_call([LinphoneManager getLc])*/) { @@ -50,7 +51,7 @@ cancelButtonTitle:NSLocalizedString(@"Continue",nil) otherButtonTitles:nil]; [error show]; - + [error release]; } else { char normalizedUserName[256]; NSString* toUserName = [NSString stringWithString:[mAddress text]]; diff --git a/Classes/LinphoneUI/UIToggleButton.h b/Classes/LinphoneUI/UIToggleButton.h index 61ba8aba7..b76550652 100644 --- a/Classes/LinphoneUI/UIToggleButton.h +++ b/Classes/LinphoneUI/UIToggleButton.h @@ -29,7 +29,6 @@ @private UIImage* mOnImage; UIImage* mOffImage; - id mActionHandler; bool mIsOn; diff --git a/Classes/PhoneViewController.m b/Classes/PhoneViewController.m index 4fc041da2..b76e61b36 100644 --- a/Classes/PhoneViewController.m +++ b/Classes/PhoneViewController.m @@ -93,10 +93,11 @@ } -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib : called twice (?!) - (void)viewDidLoad { [super viewDidLoad]; + [mDisplayName release]; mDisplayName = [UILabel alloc]; [zero initWithNumber:'0' addressField:address dtmf:false]; [one initWithNumber:'1' addressField:address dtmf:false];