From 39aa247226f32b8116b7512fd89b633e39fba48c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 8 Feb 2013 00:54:08 -0800 Subject: [PATCH] Fixed bug 1689 - Leaks galore in OS X Cocoa code. Edward Rudd This is to document the various leaks I'm finding in the Cocoa code in SDL 2. --- src/video/cocoa/SDL_cocoaevents.m | 1 + src/video/cocoa/SDL_cocoamessagebox.m | 2 +- src/video/cocoa/SDL_cocoamodes.m | 11 ++++++++--- src/video/cocoa/SDL_cocoavideo.m | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index e0865f674..8434a9dcf 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -107,6 +107,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam [menuItem setSubmenu:serviceMenu]; [NSApp setServicesMenu:serviceMenu]; + [serviceMenu release]; [appleMenu addItem:[NSMenuItem separatorItem]]; diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m index 0b60a98de..0ffa1ce79 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.m +++ b/src/video/cocoa/SDL_cocoamessagebox.m @@ -56,7 +56,7 @@ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; int i; for (i = 0; i < messageboxdata->numbuttons; ++i) { - NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]]; + NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]]; if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { [button setKeyEquivalent:@"\r"]; } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) { diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index db34d71c4..4d9a734a5 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -225,11 +225,13 @@ - (void) setFrame:(NSRect)frame; { NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName); NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]]; - + const char* displayName = NULL; + if ([localizedNames count] > 0) { - return [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]; + displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]); } - return NULL; + [deviceInfo release]; + return displayName; } void @@ -302,9 +304,11 @@ - (void) setFrame:(NSRect)frame; displaydata->display = displays[i]; SDL_zero(display); + // this returns a stddup'ed string display.name = (char *)Cocoa_GetDisplayName(displays[i]); if (!GetDisplayMode (_this, moderef, &mode)) { Cocoa_ReleaseDisplayMode(_this, moderef); + if (display.name) SDL_free(display.name); SDL_free(displaydata); continue; } @@ -313,6 +317,7 @@ - (void) setFrame:(NSRect)frame; display.current_mode = mode; display.driverdata = displaydata; SDL_AddVideoDisplay(&display); + if (display.name) SDL_free(display.name); } } SDL_stack_free(displays); diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index be72facf2..49603c699 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -273,6 +273,7 @@ void SDL_NSLog(const char *text) [alert addButtonWithTitle:@"Ignore"]; [alert addButtonWithTitle:@"Always Ignore"]; const NSInteger clicked = [alert runModal]; + [alert release]; if (!initialized) { SDL_QuitSubSystem(SDL_INIT_VIDEO);