Fix objC memory leaks

This commit is contained in:
Pierre-Eric Pelloux-Prayer 2012-01-06 10:43:23 +01:00
parent 6a6ca627ac
commit 4325741e61
13 changed files with 61 additions and 33 deletions

View file

@ -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];
}

View file

@ -156,6 +156,7 @@ NSTimer *callQualityRefresher;
[cell.accessoryView addSubview:callquality];
tableView.rowHeight = 80;//cell.bounds.size.height;
[callquality release];
return cell;
}

View file

@ -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];
}

View file

@ -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;
}

View file

@ -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"];

View file

@ -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;

View file

@ -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];

View file

@ -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);
}

View file

@ -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;

View file

@ -22,7 +22,6 @@
@interface UICallButton : UIButton {
@private
char mDigit;
UITextField* mAddress;
}
-(void) initWithAddress:(UITextField*) address;

View file

@ -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]];

View file

@ -29,7 +29,6 @@
@private
UIImage* mOnImage;
UIImage* mOffImage;
id<UIToggleButtonDelegate> mActionHandler;
bool mIsOn;

View file

@ -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];