summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-29 19:16:02 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-29 19:16:02 +0000
commit3e3a841cee601493af68af50c350c1d375701230 (patch)
treec332c6f461a3dc0869e9c46fa462a26ea343bd56
parent5c466700361ce360fd19bbc87e2cf7d90311669c (diff)
downloadpcsxr-3e3a841cee601493af68af50c350c1d375701230.tar.gz
fixed a memory leak in non-ARC code.
When we fail, autorelease, not just release self. Change createMenuItem: to newMenuItem: this makes ARC know we are returning a non-autoreleased object. It's bad practice to remove items from the array we're iterating over. the itemArray call might keep a local copy, but it still makes me cringe. Create an autorelease pool around plug-in initialization code. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@82589 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rwxr-xr-xmacosx/PcsxrPlugin.m10
-rwxr-xr-xmacosx/PluginList.m27
-rwxr-xr-xmacosx/RecentItemsMenu.h2
-rwxr-xr-xmacosx/RecentItemsMenu.m26
4 files changed, 37 insertions, 28 deletions
diff --git a/macosx/PcsxrPlugin.m b/macosx/PcsxrPlugin.m
index baa5e626..8fdd0763 100755
--- a/macosx/PcsxrPlugin.m
+++ b/macosx/PcsxrPlugin.m
@@ -110,7 +110,7 @@
NSFileManager *fm = [NSFileManager defaultManager];
- pluginRef = nil;
+ pluginRef = NULL;
name = nil;
path = [aPath copy];
NSString *goodPath = nil;
@@ -145,13 +145,13 @@
}
if (goodPath == nil) {
- RELEASEOBJ(self);
+ AUTORELEASEOBJNORETURN(self);
return nil;
}
pluginRef = SysLoadLibrary([goodPath fileSystemRepresentation]);
if (pluginRef == NULL) {
- RELEASEOBJ(self);
+ AUTORELEASEOBJNORETURN(self);
return nil;
}
@@ -169,13 +169,13 @@
else if (([path rangeOfString: @"net" options:NSCaseInsensitiveSearch]).length != 0)
type = PSE_LT_NET;
else {
- RELEASEOBJ(self);
+ AUTORELEASEOBJNORETURN(self);
return nil;
}
} else {
type = (int)PSE_getLibType();
if (type != PSE_LT_GPU && type != PSE_LT_CDR && type != PSE_LT_SPU && type != PSE_LT_PAD && type != PSE_LT_NET) {
- RELEASEOBJ(self);
+ AUTORELEASEOBJNORETURN(self);
return nil;
}
}
diff --git a/macosx/PluginList.m b/macosx/PluginList.m
index 9f2a7460..330f8be7 100755
--- a/macosx/PluginList.m
+++ b/macosx/PluginList.m
@@ -111,13 +111,16 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
continue;
if (![self hasPluginAtPath:path]) {
- PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:path];
- if (plugin) {
- [pluginList addObject:plugin];
- if (![self setActivePlugin:plugin forType:typeList[i]])
+ @autoreleasepool {
+ PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:path];
+ if (plugin) {
+ [pluginList addObject:plugin];
+ if (![self setActivePlugin:plugin forType:typeList[i]])
+ missingPlugins = YES;
+ RELEASEOBJ(plugin);
+ } else {
missingPlugins = YES;
- } else {
- missingPlugins = YES;
+ }
}
}
}
@@ -152,7 +155,7 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
- (void)refreshPlugins
{
NSDirectoryEnumerator *dirEnum;
- NSString *pname, *dir;
+ NSString *pname;
NSUInteger i;
// verify that the ones that are in list still works
@@ -174,10 +177,12 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
directory */
if (![self hasPluginAtPath:pname]) {
- PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:pname];
- if (plugin != nil) {
- [pluginList addObject:plugin];
- RELEASEOBJ(plugin);
+ @autoreleasepool {
+ PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:pname];
+ if (plugin != nil) {
+ [pluginList addObject:plugin];
+ RELEASEOBJ(plugin);
+ }
}
}
}
diff --git a/macosx/RecentItemsMenu.h b/macosx/RecentItemsMenu.h
index 220380c0..3b51c2e3 100755
--- a/macosx/RecentItemsMenu.h
+++ b/macosx/RecentItemsMenu.h
@@ -15,7 +15,7 @@
- (IBAction)clearRecentDocuments:(id)sender;
- (void)addRecentItem:(NSURL*)documentURL;
-- (NSMenuItem*)createMenuItem:(NSURL*)documentURL;
+- (NSMenuItem*)newMenuItem:(NSURL*)documentURL;
- (void)openRecentItem:(NSMenuItem*)sender;
- (void)addMenuItem:(NSMenuItem*)item;
diff --git a/macosx/RecentItemsMenu.m b/macosx/RecentItemsMenu.m
index 136895c2..357ebd65 100755
--- a/macosx/RecentItemsMenu.m
+++ b/macosx/RecentItemsMenu.m
@@ -20,8 +20,8 @@
// Populate the menu
NSArray* recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
NSInteger index = 0;
- for(NSURL* url in recentDocuments) {
- NSMenuItem *tempItem = [self createMenuItem:url];
+ for (NSURL* url in recentDocuments) {
+ NSMenuItem *tempItem = [self newMenuItem:url];
[self addMenuItem:tempItem atIndex:index];
RELEASEOBJ(tempItem);
index++;
@@ -33,12 +33,12 @@
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:documentURL];
NSMenuItem* item = RETAINOBJ([self findMenuItemByURL:documentURL]);
- if(item != nil) {
+ if (item != nil) {
[self removeItem:item];
[self insertItem:item atIndex:0];
RELEASEOBJ(item);
} else {
- NSMenuItem *newitem = [self createMenuItem:documentURL];
+ NSMenuItem *newitem = [self newMenuItem:documentURL];
[self addMenuItem:newitem];
RELEASEOBJ(newitem);
}
@@ -50,7 +50,7 @@
// Prevent menu from overflowing; the -2 accounts for the "Clear..." and the separator items
NSInteger maxNumItems = [[NSDocumentController sharedDocumentController] maximumRecentDocumentCount];
- if(([self numberOfItems]-2) > maxNumItems) {
+ if (([self numberOfItems] - 2) > maxNumItems) {
[self removeItemAtIndex:maxNumItems];
}
}
@@ -71,7 +71,7 @@
[self insertItem:item atIndex:index]; // insert at the top
}
-- (NSMenuItem*)createMenuItem:(NSURL*)documentURL
+- (NSMenuItem*)newMenuItem:(NSURL*)documentURL
{
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:[documentURL lastPathComponent] action:@selector(openRecentItem:) keyEquivalent:@""];
[newItem setRepresentedObject:documentURL];
@@ -97,11 +97,15 @@
// Document items are menu items with tag 0
- (void)removeDocumentItems
{
- for(NSMenuItem* item in [self itemArray]) {
- if([item tag] == 0) {
- [self removeItem:item];
- }
- }
+ NSMutableArray *removeItemsArray = [NSMutableArray array];
+ for (NSMenuItem* item in [self itemArray]) {
+ if([item tag] == 0) {
+ [removeItemsArray addObject:item];
+ }
+ }
+ for (NSMenuItem *item in removeItemsArray) {
+ [self removeItem:item];
+ }
}
@end