Fix memory leaks spotted by clang static analysis.

Refactored imageSharing to adopt objc conventions: the name of a method returning an allocated object has to contain 'new'
This commit is contained in:
Guillaume BIENKOWSKI 2014-05-14 16:12:59 +02:00
parent e78e786646
commit 40a69c033c
19 changed files with 69 additions and 58 deletions

View file

@ -392,13 +392,12 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
[waitView setHidden:TRUE];
if (error) {
[LinphoneLogger log:LinphoneLoggerError format:@"Cannot save image data downloaded [%@]", [error localizedDescription]];
UIAlertView* errorAlert = [UIAlertView alloc];
[errorAlert initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot write image to photo library", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot write image to photo library", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
[errorAlert show];
[errorAlert release];
return;
@ -655,7 +654,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
- (BOOL)chatRoomStartImageDownload:(NSURL*)url userInfo:(id)userInfo {
if(imageSharing == nil) {
imageSharing = [ImageSharing imageSharingDownload:url delegate:self userInfo:userInfo];
imageSharing = [ImageSharing newImageSharingDownload:url delegate:self userInfo:userInfo];
[messageView setHidden:TRUE];
[transferView setHidden:FALSE];
return TRUE;
@ -666,7 +665,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
- (BOOL)chatRoomStartImageUpload:(UIImage*)image url:(NSURL*)url{
if(imageSharing == nil) {
NSString *urlString = [[LinphoneManager instance] lpConfigStringForKey:@"sharing_server_preference"];
imageSharing = [ImageSharing imageSharingUpload:[NSURL URLWithString:urlString] image:image delegate:self userInfo:url];
imageSharing = [ImageSharing newImageSharingUpload:[NSURL URLWithString:urlString] image:image delegate:self userInfo:url];
[messageView setHidden:TRUE];
[transferView setHidden:FALSE];
return TRUE;
@ -687,7 +686,8 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
- (void)imageSharingAborted:(ImageSharing*)aimageSharing {
[messageView setHidden:FALSE];
[transferView setHidden:TRUE];
imageSharing = NULL;
[imageSharing release];
imageSharing = nil;
}
- (void)imageSharingError:(ImageSharing*)aimageSharing error:(NSError *)error {
@ -696,26 +696,24 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
NSString *url = [aimageSharing.connection.currentRequest.URL absoluteString];
if (aimageSharing.upload) {
[LinphoneLogger log:LinphoneLoggerError format:@"Cannot upload file to server [%@] because [%@]", url, [error localizedDescription]];
UIAlertView* errorAlert = [UIAlertView alloc];
[errorAlert initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot transfer file to remote contact", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot transfer file to remote contact", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
[errorAlert show];
[errorAlert release];
} else {
[LinphoneLogger log:LinphoneLoggerError format:@"Cannot dowanlod file from [%@] because [%@]", url, [error localizedDescription]];
UIAlertView* errorAlert = [UIAlertView alloc];
[errorAlert initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot transfer file from remote contact", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Continue", nil)
otherButtonTitles:nil, nil];
UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot transfer file from remote contact", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Continue", nil)
otherButtonTitles:nil, nil];
[errorAlert show];
[errorAlert release];
}
imageSharing = NULL;
imageSharing = nil;
}
- (void)imageSharingUploadDone:(ImageSharing*)aimageSharing url:(NSURL*)url{
@ -725,7 +723,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
[messageView setHidden:FALSE];
[transferView setHidden:TRUE];
imageSharing = NULL;
imageSharing = nil;
}
- (void)imageSharingDownloadDone:(ImageSharing*)aimageSharing image:(UIImage *)image {
@ -738,13 +736,12 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
[LinphoneLogger log:LinphoneLoggerError format:@"Cannot save image data downloaded [%@]", [error localizedDescription]];
UIAlertView* errorAlert = [UIAlertView alloc];
[errorAlert initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot write image to photo library", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil)
message:NSLocalizedString(@"Cannot write image to photo library", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil)
otherButtonTitles:nil ,nil];
[errorAlert show];
[errorAlert release];
return;
@ -754,7 +751,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
[chat update];
[tableController updateChatEntry:chat];
}];
imageSharing = NULL;
imageSharing = nil;
}

View file

@ -276,13 +276,17 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0];
ABMultiValueAddValueAndLabel(lMap, lDict, label, &index);
}
if (!ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) {
[LinphoneLogger log:LinphoneLoggerLog format:@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]];
CFRelease(lMap);
} else {
if (entry == nil) {
entry = [[Entry alloc] initWithData:index];
entry = [[[Entry alloc] initWithData:index] autorelease];
}
CFRelease(lDict);
CFRelease(lMap);
/*check if message type is kept or not*/
lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty);
lMap = ABMultiValueCreateMutableCopy(lcMap);
@ -308,12 +312,13 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
ms_free(uri);
}
}
CFRelease(lMap);
CFRelease(lMap);
}
CFRelease(lDict);
return entry;
}
-(void) setSipContactEntry:(Entry *)entry withValue:(NSString*)value {
[self setOrCreateSipContactEntry:entry withValue:value];
}
@ -337,7 +342,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
lMap = ABMultiValueCreateMutable(kABStringPropertyType);
}
CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0];
if(!ABMultiValueAddValueAndLabel(lMap, [value copy], label, &identifier)) {
if(!ABMultiValueAddValueAndLabel(lMap, [[value copy] autorelease], label, &identifier)) {
added = false;
}
@ -354,7 +359,6 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
Entry *entry = [self setOrCreateSipContactEntry:nil withValue:value];
if (entry) {
[sectionArray addObject:entry];
[entry release];
added=true;
} else {
added=false;
@ -371,7 +375,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
lMap = ABMultiValueCreateMutable(kABStringPropertyType);
}
CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0];
if(!ABMultiValueAddValueAndLabel(lMap, [value copy], label, &identifier)) {
if(!ABMultiValueAddValueAndLabel(lMap, [[value copy] autorelease], label, &identifier)) {
added = false;
}

View file

@ -111,12 +111,14 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
}
CFRelease(lDict);
}
CFRelease(lMap);
}
if ((add == false) && [ContactSelection getEmailFilter]) {
ABMultiValueRef lMap = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonEmailProperty);
if (ABMultiValueGetCount(lMap) > 0) {
add = true;
}
CFRelease(lMap);
}
if(add) {
CFStringRef lFirstName = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonFirstNameProperty);

View file

@ -154,8 +154,8 @@ static UICompositeViewDescription *compositeDescription = nil;
// let the toolBar be visible
subViewFrame.origin.y += self.toolBar.frame.size.height;
self.tableController = [[ContactsTableViewController alloc] init];
self.tableView = [[UITableView alloc] init];
self.tableController = [[[ContactsTableViewController alloc] init] autorelease];
self.tableView = [[[UITableView alloc] init] autorelease];
self.tableController.view = self.tableView;
self.tableView.frame = subViewFrame;
@ -309,7 +309,7 @@ static UICompositeViewDescription *compositeDescription = nil;
// Go to dialer view
DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController);
if(controller != nil) {
[controller call:phoneNumber displayName:(NSString*)ABRecordCopyCompositeName(person)];
[controller call:phoneNumber displayName:[(NSString*)ABRecordCopyCompositeName(person) autorelease]];
}
[phoneNumber release];
CFRelease(multiValue);

View file

@ -162,9 +162,11 @@ static UICompositeViewDescription *compositeDescription = nil;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
// fix placeholder bar color in iOS7
UIColor *color = [UIColor grayColor];
addressField.attributedPlaceholder = [[NSAttributedString alloc]
initWithString:NSLocalizedString(@"Enter an address", @"Enter an address")
attributes:@{NSForegroundColorAttributeName: color}];
NSAttributedString* placeHolderString = [[NSAttributedString alloc]
initWithString:NSLocalizedString(@"Enter an address", @"Enter an address")
attributes:@{NSForegroundColorAttributeName: color}];
addressField.attributedPlaceholder = placeHolderString;
[placeHolderString release];
}
#endif

View file

@ -38,8 +38,8 @@
int statusCode;
}
+ (id)imageSharingUpload:(NSURL*)url image:(UIImage*)image delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)userInfo;
+ (id)imageSharingDownload:(NSURL*)url delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)userInfo;
+ (id)newImageSharingUpload:(NSURL*)url image:(UIImage*)image delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)userInfo;
+ (id)newImageSharingDownload:(NSURL*)url delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)userInfo;
- (void)cancel;

View file

@ -30,7 +30,7 @@
#pragma mark - Lifecycle Functions
+ (id)imageSharingUpload:(NSURL*)url image:(UIImage*)image delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)auserInfo{
+ (id)newImageSharingUpload:(NSURL*)url image:(UIImage*)image delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)auserInfo{
ImageSharing *imgs = [[ImageSharing alloc] init];
if(imgs != nil) {
imgs.userInfo = auserInfo;
@ -45,7 +45,7 @@
return imgs;
}
+ (id)imageSharingDownload:(NSURL*)url delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)auserInfo{
+ (id)newImageSharingDownload:(NSURL*)url delegate:(id<ImageSharingDelegate>)delegate userInfo:(id)auserInfo{
ImageSharing *imgs = [[ImageSharing alloc] init];
if(imgs != nil) {
imgs.userInfo = auserInfo;
@ -173,6 +173,7 @@
if(delegate) {
[delegate imageSharingUploadDone:self url:[NSURL URLWithString:imageRemoteUrl]];
}
[imageRemoteUrl release];
} else {
UIImage* image = [UIImage imageWithData:data];
[LinphoneLogger log:LinphoneLoggerLog format:@"File downloaded"];

View file

@ -382,6 +382,7 @@
[_waitingIndicator addSubview:progress];
}
[progress startAnimating];
[progress release];
[_waitingIndicator show];
}

View file

@ -49,7 +49,8 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
- (void)setString:(const char*)value forKey:(NSString*)key {
id obj=Nil;
if (value) obj=[[NSString alloc] initWithCString:value encoding:[NSString defaultCStringEncoding] ];
[self setObject: obj forKey:key];
[self setObject:obj forKey:key];
[obj release];
}
- (NSString*)stringForKey:(NSString*) key {

View file

@ -332,7 +332,6 @@ struct codec_name_pref_table codec_pref_table[]={
}
}
[filemgr release];
}
- (void)closeDatabase {

View file

@ -147,7 +147,7 @@
options:nil];
if ([arrayOfViews count] >= 1) {
[self addSubview:[[arrayOfViews objectAtIndex:0] retain]];
[self.contentView addSubview:[arrayOfViews objectAtIndex:0]];
}
// Set selected+over background: IB lack !
[pauseButton setImage:[UIImage imageNamed:@"call_state_pause_over.png"]
@ -513,7 +513,7 @@
if(parentTable != nil) {
NSIndexPath *index= [parentTable indexPathForCell:self];
if(index != nil) {
[parentTable reloadRowsAtIndexPaths:[[NSArray alloc] initWithObjects:index, nil] withRowAnimation:false];
[parentTable reloadRowsAtIndexPaths:[[[NSArray alloc] initWithObjects:index, nil] autorelease] withRowAnimation:false];
}
}
}

View file

@ -42,7 +42,8 @@
options:nil];
if ([arrayOfViews count] >= 1) {
[self addSubview:[[arrayOfViews objectAtIndex:0] retain]];
[self.contentView addSubview:[arrayOfViews objectAtIndex:0]];
}
[chatContentLabel setAdjustsFontSizeToFitWidth:TRUE]; // Auto shrink: IB lack!
}

View file

@ -191,6 +191,7 @@ static UIFont *CELL_FONT = nil;
initWithString:NSLocalizedString(@"Resend", @"Resend")
attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}];
[dateLabel setAttributedText:resend_text];
[resend_text release];
} else {
statusImage.hidden = TRUE;
}

View file

@ -38,7 +38,7 @@
options:nil];
if ([arrayOfViews count] >= 1) {
[self addSubview:[[arrayOfViews objectAtIndex:0] retain]];
[self.contentView addSubview:[arrayOfViews objectAtIndex:0] ];
}
}
return self;

View file

@ -58,7 +58,7 @@
}
- (void)dealloc {
[self.detailTextField release];
self.detailTextField = nil;
[super dealloc];
}

View file

@ -39,7 +39,7 @@
options:nil];
if ([arrayOfViews count] >= 1) {
[self addSubview:[[arrayOfViews objectAtIndex:0] retain]];
[self.contentView addSubview:[arrayOfViews objectAtIndex:0]];
}
self->callLog = NULL;

View file

@ -365,6 +365,7 @@
labelTitleView.text = viewController.title;
[labelTitleView sizeToFit];
viewController.navigationItem.titleView = labelTitleView;
[labelTitleView release];
[super pushViewController:viewController animated:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[self.topViewController viewDidAppear:animated];
@ -703,7 +704,7 @@ static UICompositeViewDescription *compositeDescription = nil;
NSString *key = [specifier.specifierDict objectForKey:kIASKKey];
#ifdef DEBUG
if([key isEqual:@"release_button"]) {
[[UIApplication sharedApplication].keyWindow.rootViewController release];
[UIApplication sharedApplication].keyWindow.rootViewController = nil;
[[UIApplication sharedApplication].keyWindow setRootViewController:nil];
[[LinphoneManager instance] destroyLibLinphone];
[LinphoneManager instanceRelease];

View file

@ -60,7 +60,7 @@
if (block)
{
NSNumber *key = [NSNumber numberWithInt:retIndex];
[_actionsPerIndex setObject:[block copy] forKey:key];
[_actionsPerIndex setObject:[[block copy] autorelease] forKey:key];
}
return retIndex;

View file

@ -358,7 +358,7 @@
if ([textToMeasure.string hasSuffix:@"\n"])
{
[textToMeasure appendAttributedString:[[NSAttributedString alloc] initWithString:@"-" attributes:@{NSFontAttributeName: internalTextView.font}]];
[textToMeasure appendAttributedString:[[[NSAttributedString alloc] initWithString:@"-" attributes:@{NSFontAttributeName: internalTextView.font}]autorelease]];
}
// NSAttributedString class method: boundingRectWithSize:options:context is
@ -366,6 +366,7 @@
CGRect size = [textToMeasure boundingRectWithSize:CGSizeMake(CGRectGetWidth(frame), MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
[textToMeasure release];
return CGRectGetHeight(size) + fudgeFactor.height;
}