cleanup: run XCode code analysis
enable ARC in CMakelist.txt
fix small potentials leaks across the client
Refs #75600
Change-Id: I72ba17e6daed393abdf38653f45c040bd3427ead
diff --git a/src/AccSecurityVC.h b/src/AccSecurityVC.h
index 96d9506..9aaf995 100644
--- a/src/AccSecurityVC.h
+++ b/src/AccSecurityVC.h
@@ -36,4 +36,4 @@
@end
-#endif // ACCSECURITYVC_H
\ No newline at end of file
+#endif // ACCSECURITYVC_H
diff --git a/src/AccSecurityVC.mm b/src/AccSecurityVC.mm
index cb4dda6..1a7f4c9 100644
--- a/src/AccSecurityVC.mm
+++ b/src/AccSecurityVC.mm
@@ -49,7 +49,7 @@
@interface AccSecurityVC ()
-@property NSTreeController *treeController;
+@property QNSTreeController *treeController;
@property (unsafe_unretained) IBOutlet NSOutlineView *cipherListView;
@property (unsafe_unretained) IBOutlet NSButton *useTLS;
@property (unsafe_unretained) IBOutlet NSView *tlsContainer;
@@ -122,11 +122,11 @@
[self updateControlsWithTag:OUTGOING_TLS_SRV_NAME];
[self updateControlsWithTag:TLS_NEGOTIATION_TAG];
- QModelIndex qTlsMethodIdx = [self currentAccount]->tlsMethodModel()->selectionModel()->currentIndex();
+ QModelIndex qTlsMethodIdx = account->tlsMethodModel()->selectionModel()->currentIndex();
[self.tlsMethodList removeAllItems];
[self.tlsMethodList addItemWithTitle:qTlsMethodIdx.data(Qt::DisplayRole).toString().toNSString()];
- treeController = [[QNSTreeController alloc] initWithQModel:[self currentAccount]->cipherModel()];
+ treeController = [[QNSTreeController alloc] initWithQModel:account->cipherModel()];
[treeController setAvoidsEmptySelection:NO];
[treeController setAlwaysUsesMultipleValuesMarker:YES];
[treeController setChildrenKeyPath:@"children"];
@@ -145,22 +145,22 @@
NSArray * pathComponentArray = [self pathComponentArray];
if([self currentAccount]->tlsCaListCertificate() != nil) {
- NSLog(@"CA ==> %@", [self currentAccount]->tlsCaListCertificate()->path().toNSURL());
- [caListPathControl setURL:[self currentAccount]->tlsCaListCertificate()->path().toNSURL()];
+ NSLog(@"CA ==> %@", account->tlsCaListCertificate()->path().toNSURL());
+ [caListPathControl setURL:account->tlsCaListCertificate()->path().toNSURL()];
} else {
[caListPathControl setURL:nil];
}
if([self currentAccount]->tlsCertificate() != nil) {
- NSLog(@" CERT ==> %@", [self currentAccount]->tlsCertificate()->path().toNSURL());
- [certificatePathControl setURL:[self currentAccount]->tlsCertificate()->path().toNSURL()];
+ NSLog(@" CERT ==> %@", account->tlsCertificate()->path().toNSURL());
+ [certificatePathControl setURL:account->tlsCertificate()->path().toNSURL()];
} else {
[certificatePathControl setURL:nil];
}
if([self currentAccount]->tlsPrivateKeyCertificate() != nil) {
- NSLog(@" PVK ==> %@", [self currentAccount]->tlsPrivateKeyCertificate()->path().toNSURL());
- [pvkPathControl setURL:[self currentAccount]->tlsPrivateKeyCertificate()->path().toNSURL()];
+ NSLog(@" PVK ==> %@", account->tlsPrivateKeyCertificate()->path().toNSURL());
+ [pvkPathControl setURL:account->tlsPrivateKeyCertificate()->path().toNSURL()];
} else {
[pvkPathControl setURL:nil];
}
diff --git a/src/AccVideoVC.mm b/src/AccVideoVC.mm
index 862e02d..7e5ed1e 100644
--- a/src/AccVideoVC.mm
+++ b/src/AccVideoVC.mm
@@ -78,15 +78,15 @@
{
auto account = [self currentAccount];
- treeController = [[QNSTreeController alloc] initWithQModel:[self currentAccount]->codecModel()->videoCodecs()];
+ treeController = [[QNSTreeController alloc] initWithQModel:account->codecModel()->videoCodecs()];
[treeController setAvoidsEmptySelection:NO];
[treeController setChildrenKeyPath:@"children"];
[codecsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
[codecsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
[codecsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
- [videoPanelContainer setHidden:![self currentAccount]->isVideoEnabled()];
- [toggleVideoButton setState:[self currentAccount]->isVideoEnabled()?NSOnState:NSOffState];
+ [videoPanelContainer setHidden:!account->isVideoEnabled()];
+ [toggleVideoButton setState:account->isVideoEnabled()?NSOnState:NSOffState];
}
- (IBAction)toggleVideoEnabled:(id)sender {
diff --git a/src/AccountsVC.mm b/src/AccountsVC.mm
index a04ddec..168e59b 100644
--- a/src/AccountsVC.mm
+++ b/src/AccountsVC.mm
@@ -178,10 +178,9 @@
- (IBAction)addAccount:(id)sender {
QModelIndex qIdx = AccountModel::instance()->protocolModel()->selectionModel()->currentIndex();
- NSString* newAccName = [[NSString alloc] initWithFormat:@"%@ account",
+ auto newAccName = [[NSString alloc] initWithFormat:@"%@ account",
AccountModel::instance()->protocolModel()->data(qIdx, Qt::DisplayRole).toString().toNSString(), nil];
-
- Account* newAcc =AccountModel::instance()->add([newAccName UTF8String], qIdx);
+ AccountModel::instance()->add([newAccName UTF8String], qIdx);
AccountModel::instance()->save();
}
@@ -270,11 +269,10 @@
if ([[tableColumn identifier] isEqualToString:COLUMNID_ENABLE] &&
AccountModel::instance()->ip2ip()->index() == qIdx) {
- returnCell = [[NSCell alloc] init];
+ return [[NSCell alloc] init];
} else {
- returnCell = [tableColumn dataCell];
+ return [tableColumn dataCell];
}
- return returnCell;
}
// -------------------------------------------------------------------------------
@@ -350,9 +348,9 @@
{
// ask the tree controller for the current selection
if([[treeController selectedNodes] count] > 0) {
- QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
+ auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
//Update details view
- Account* acc = AccountModel::instance()->getAccountByModelIndex(qIdx);
+ auto acc = AccountModel::instance()->getAccountByModelIndex(qIdx);
AccountModel::instance()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect);
switch (acc->protocol()) {
diff --git a/src/GeneralPrefsVC.h b/src/GeneralPrefsVC.h
index ef059ae..cffd689 100644
--- a/src/GeneralPrefsVC.h
+++ b/src/GeneralPrefsVC.h
@@ -32,10 +32,7 @@
#import <Cocoa/Cocoa.h>
-@interface GeneralPrefsVC : NSViewController {
-
- NSTextField *historyChangedLabel;
-}
+@interface GeneralPrefsVC : NSViewController
@end
diff --git a/src/GeneralPrefsVC.mm b/src/GeneralPrefsVC.mm
index 2cf7cdd..b4c9d35 100644
--- a/src/GeneralPrefsVC.mm
+++ b/src/GeneralPrefsVC.mm
@@ -34,8 +34,8 @@
#import "Constants.h"
@interface GeneralPrefsVC ()
-@property (assign) IBOutlet NSTextField *historyChangedLabel;
-@property (assign) IBOutlet NSView *advancedGeneralSettings;
+@property (unsafe_unretained) IBOutlet NSTextField *historyChangedLabel;
+@property (unsafe_unretained) IBOutlet NSView *advancedGeneralSettings;
@property (unsafe_unretained) IBOutlet NSButton *startUpButton;
@end
@@ -56,6 +56,12 @@
[advancedGeneralSettings setHidden:![[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]];
}
+- (void) dealloc
+{
+ [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::HistoryLimit];
+ [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::ShowAdvanced];
+}
+
- (IBAction)clearHistory:(id)sender {
CategorizedHistoryModel::instance()->clearAllCollections();
[historyChangedLabel setHidden:NO];
@@ -94,7 +100,7 @@
if (loginItemsRef == nil) return;
if (shouldBeToggled) {
// Add the app to the LoginItems list.
- CFURLRef appUrl = (CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
+ CFURLRef appUrl = (__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSSharedFileListItemRef itemRef = LSSharedFileListInsertItemURL(loginItemsRef, kLSSharedFileListItemLast, NULL, NULL, appUrl, NULL, NULL);
if (itemRef) CFRelease(itemRef);
}
@@ -109,21 +115,21 @@
- (LSSharedFileListItemRef)itemRefInLoginItems {
LSSharedFileListItemRef itemRef = nil;
- NSURL *itemUrl = nil;
+ CFURLRef itemUrl = nil;
// Get the app's URL.
- NSURL *appUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
+ auto appUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
// Get the LoginItems list.
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItemsRef == nil) return nil;
// Iterate over the LoginItems.
- NSArray *loginItems = (NSArray *)LSSharedFileListCopySnapshot(loginItemsRef, nil);
+ NSArray *loginItems = (__bridge_transfer NSArray *)LSSharedFileListCopySnapshot(loginItemsRef, nil);
for (int currentIndex = 0; currentIndex < [loginItems count]; currentIndex++) {
// Get the current LoginItem and resolve its URL.
- LSSharedFileListItemRef currentItemRef = (LSSharedFileListItemRef)[loginItems objectAtIndex:currentIndex];
- if (LSSharedFileListItemResolve(currentItemRef, 0, (CFURLRef *) &itemUrl, NULL) == noErr) {
+ LSSharedFileListItemRef currentItemRef = (__bridge LSSharedFileListItemRef)[loginItems objectAtIndex:currentIndex];
+ if (LSSharedFileListItemResolve(currentItemRef, 0, &itemUrl, NULL) == noErr) {
// Compare the URLs for the current LoginItem and the app.
- if ([itemUrl isEqual:appUrl]) {
+ if ([(__bridge NSURL *)itemUrl isEqual:appUrl]) {
// Save the LoginItem reference.
itemRef = currentItemRef;
}
@@ -132,7 +138,6 @@
// Retain the LoginItem reference.
if (itemRef != nil) CFRetain(itemRef);
// Release the LoginItems lists.
- [loginItems release];
CFRelease(loginItemsRef);
return itemRef;
diff --git a/src/HistoryVC.mm b/src/HistoryVC.mm
index fbdd78e..acb41c4 100644
--- a/src/HistoryVC.mm
+++ b/src/HistoryVC.mm
@@ -44,7 +44,7 @@
@interface HistoryVC()
-@property NSTreeController *treeController;
+@property QNSTreeController *treeController;
@property (assign) IBOutlet NSOutlineView *historyView;
@property QSortFilterProxyModel *historyProxyModel;
@end
diff --git a/src/PersonsVC.mm b/src/PersonsVC.mm
index bf9e6b4..f1d1c26 100644
--- a/src/PersonsVC.mm
+++ b/src/PersonsVC.mm
@@ -62,7 +62,7 @@
@interface PersonsVC ()
-@property NSTreeController *treeController;
+@property QNSTreeController *treeController;
@property (assign) IBOutlet NSOutlineView *personsView;
@property QSortFilterProxyModel *contactProxyModel;
diff --git a/src/PreferencesVC.h b/src/PreferencesVC.h
index e763caa..4b2ecf9 100644
--- a/src/PreferencesVC.h
+++ b/src/PreferencesVC.h
@@ -34,11 +34,11 @@
@interface PreferencesVC : NSViewController <NSToolbarDelegate>
-@property (nonatomic, assign) NSViewController *currentVC;
-@property (nonatomic, assign) NSViewController *accountsPrefsVC;
-@property (nonatomic, assign) NSViewController *generalPrefsVC;
-@property (nonatomic, assign) NSViewController *audioPrefsVC;
-@property (nonatomic, assign) NSViewController *videoPrefsVC;
+@property (nonatomic, strong) NSViewController *currentVC;
+@property (nonatomic, strong) NSViewController *accountsPrefsVC;
+@property (nonatomic, strong) NSViewController *generalPrefsVC;
+@property (nonatomic, strong) NSViewController *audioPrefsVC;
+@property (nonatomic, strong) NSViewController *videoPrefsVC;
- (void) close;
- (void)displayGeneral:(NSToolbarItem *)sender;
diff --git a/src/QNSTreeController.mm b/src/QNSTreeController.mm
index eca4884..f7697fb 100644
--- a/src/QNSTreeController.mm
+++ b/src/QNSTreeController.mm
@@ -55,7 +55,7 @@
- (id) initWithQModel:(QAbstractItemModel*) model
{
- [super init];
+ self = [super init];
self->privateQModel = model;
topNodes = [[NSMutableArray alloc] init];
diff --git a/src/RingWizardWC.h b/src/RingWizardWC.h
index e3ca858..28f3755 100644
--- a/src/RingWizardWC.h
+++ b/src/RingWizardWC.h
@@ -30,9 +30,6 @@
#import <Cocoa/Cocoa.h>
-@interface RingWizardWC : NSWindowController <NSWindowDelegate>{
-
- NSButton *goToAppButton;
-}
+@interface RingWizardWC : NSWindowController <NSWindowDelegate>
@end
diff --git a/src/RingWizardWC.mm b/src/RingWizardWC.mm
index b3b03dd..5868bc6 100644
--- a/src/RingWizardWC.mm
+++ b/src/RingWizardWC.mm
@@ -38,11 +38,11 @@
@interface RingWizardWC ()
-@property (assign) IBOutlet NSButton *goToAppButton;
-@property (assign) IBOutlet NSTextField *nickname;
-@property (assign) IBOutlet NSProgressIndicator *progressBar;
-@property (assign) IBOutlet NSTextField *indicationLabel;
-@property (assign) IBOutlet NSButton *createButton;
+@property (unsafe_unretained) IBOutlet NSButton *goToAppButton;
+@property (unsafe_unretained) IBOutlet NSTextField *nickname;
+@property (unsafe_unretained) IBOutlet NSProgressIndicator *progressBar;
+@property (unsafe_unretained) IBOutlet NSTextField *indicationLabel;
+@property (unsafe_unretained) IBOutlet NSButton *createButton;
@end
@implementation RingWizardWC
@@ -112,7 +112,7 @@
{
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItemsRef == nil) return;
- CFURLRef appUrl = (CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
+ CFURLRef appUrl = (__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSSharedFileListItemRef itemRef = LSSharedFileListInsertItemURL(loginItemsRef, kLSSharedFileListItemLast, NULL, NULL, appUrl, NULL, NULL);
if (itemRef) CFRelease(itemRef);
}
diff --git a/src/delegates/ImageManipulationDelegate.mm b/src/delegates/ImageManipulationDelegate.mm
index fb0b91e..40f7a0a 100644
--- a/src/delegates/ImageManipulationDelegate.mm
+++ b/src/delegates/ImageManipulationDelegate.mm
@@ -125,11 +125,14 @@
QPainter painter(&pxm);
// create the image somehow, load from file, draw into it...
- CGImageSourceRef source;
+ auto sourceImgRef = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL);
+ auto imgRef = CGImageSourceCreateImageAtIndex(sourceImgRef, 0, NULL);
+ auto finalImgRef = resizeCGImage(imgRef, size);
+ painter.drawPixmap(3,3,QtMac::fromCGImageRef(finalImgRef));
- source = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL);
- CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
- painter.drawPixmap(3,3,QtMac::fromCGImageRef(resizeCGImage(maskRef, size)));
+ CFRelease(sourceImgRef);
+ CFRelease(imgRef);
+ CFRelease(finalImgRef);
return pxm;
}
@@ -143,8 +146,6 @@
size.width() * CGImageGetBitsPerComponent(image),
colorspace,
CGImageGetAlphaInfo(image));
- CGColorSpaceRelease(colorspace);
-
if(context == NULL)
return nil;
diff --git a/src/views/CallView.mm b/src/views/CallView.mm
index 43a5d80..8fe60c6 100644
--- a/src/views/CallView.mm
+++ b/src/views/CallView.mm
@@ -73,7 +73,7 @@
NSLog(@"Dragging entered");
NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
- CFStringRef fileExtension = (CFStringRef) [fileURL.path pathExtension];
+ CFStringRef fileExtension = (__bridge CFStringRef) [fileURL.path pathExtension];
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
// Check if the pasteboard contains image data and source/user wants it copied
@@ -94,11 +94,12 @@
usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop) {
*stop = YES;
}];
-
+ CFRelease(fileUTI);
//accept data as a copy operation
return NSDragOperationCopy;
}
+ CFRelease(fileUTI);
return NSDragOperationNone;
}
@@ -140,11 +141,13 @@
[self setNeedsDisplay: YES];
NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
- CFStringRef fileExtension = (CFStringRef) [fileURL.path pathExtension];
+ CFStringRef fileExtension = (__bridge CFStringRef) [fileURL.path pathExtension];
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
+ BOOL conforms = (UTTypeConformsTo(fileUTI, kUTTypeVideo)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie));
+ CFRelease(fileUTI);
//check to see if we can accept the data
- return (UTTypeConformsTo(fileUTI, kUTTypeVideo)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie));
+ return conforms;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender