Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1689 - Leaks galore in OS X Cocoa code.
Browse files Browse the repository at this point in the history
Edward Rudd

This is to document the various leaks I'm finding in the Cocoa code in SDL 2.
  • Loading branch information
slouken committed Feb 8, 2013
1 parent e740ffe commit 39aa247
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -107,6 +107,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
[menuItem setSubmenu:serviceMenu];

[NSApp setServicesMenu:serviceMenu];
[serviceMenu release];

[appleMenu addItem:[NSMenuItem separatorItem]];

Expand Down
2 changes: 1 addition & 1 deletion src/video/cocoa/SDL_cocoamessagebox.m
Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions src/video/cocoa/SDL_cocoamodes.m
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -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);
Expand Down

0 comments on commit 39aa247

Please sign in to comment.