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.
1.1 --- a/src/video/cocoa/SDL_cocoaevents.m Tue Feb 05 12:10:54 2013 -0800
1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m Fri Feb 08 00:54:08 2013 -0800
1.3 @@ -107,6 +107,7 @@
1.4 [menuItem setSubmenu:serviceMenu];
1.5
1.6 [NSApp setServicesMenu:serviceMenu];
1.7 + [serviceMenu release];
1.8
1.9 [appleMenu addItem:[NSMenuItem separatorItem]];
1.10
2.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m Tue Feb 05 12:10:54 2013 -0800
2.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m Fri Feb 08 00:54:08 2013 -0800
2.3 @@ -56,7 +56,7 @@
2.4 const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
2.5 int i;
2.6 for (i = 0; i < messageboxdata->numbuttons; ++i) {
2.7 - NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
2.8 + NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
2.9 if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
2.10 [button setKeyEquivalent:@"\r"];
2.11 } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
3.1 --- a/src/video/cocoa/SDL_cocoamodes.m Tue Feb 05 12:10:54 2013 -0800
3.2 +++ b/src/video/cocoa/SDL_cocoamodes.m Fri Feb 08 00:54:08 2013 -0800
3.3 @@ -225,11 +225,13 @@
3.4 {
3.5 NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
3.6 NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
3.7 -
3.8 + const char* displayName = NULL;
3.9 +
3.10 if ([localizedNames count] > 0) {
3.11 - return [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String];
3.12 + displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
3.13 }
3.14 - return NULL;
3.15 + [deviceInfo release];
3.16 + return displayName;
3.17 }
3.18
3.19 void
3.20 @@ -302,9 +304,11 @@
3.21 displaydata->display = displays[i];
3.22
3.23 SDL_zero(display);
3.24 + // this returns a stddup'ed string
3.25 display.name = (char *)Cocoa_GetDisplayName(displays[i]);
3.26 if (!GetDisplayMode (_this, moderef, &mode)) {
3.27 Cocoa_ReleaseDisplayMode(_this, moderef);
3.28 + if (display.name) SDL_free(display.name);
3.29 SDL_free(displaydata);
3.30 continue;
3.31 }
3.32 @@ -313,6 +317,7 @@
3.33 display.current_mode = mode;
3.34 display.driverdata = displaydata;
3.35 SDL_AddVideoDisplay(&display);
3.36 + if (display.name) SDL_free(display.name);
3.37 }
3.38 }
3.39 SDL_stack_free(displays);
4.1 --- a/src/video/cocoa/SDL_cocoavideo.m Tue Feb 05 12:10:54 2013 -0800
4.2 +++ b/src/video/cocoa/SDL_cocoavideo.m Fri Feb 08 00:54:08 2013 -0800
4.3 @@ -273,6 +273,7 @@
4.4 [alert addButtonWithTitle:@"Ignore"];
4.5 [alert addButtonWithTitle:@"Always Ignore"];
4.6 const NSInteger clicked = [alert runModal];
4.7 + [alert release];
4.8
4.9 if (!initialized) {
4.10 SDL_QuitSubSystem(SDL_INIT_VIDEO);