Fixed bug 1689 - Leaks galore in OS X Cocoa code.
authorSam Lantinga <slouken@libsdl.org>
Fri, 08 Feb 2013 00:54:08 -0800
changeset 6836 b0ca1571caf3
parent 6835 c259f0817583
child 6837 a69e10925a58
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
src/video/cocoa/SDL_cocoamessagebox.m
src/video/cocoa/SDL_cocoamodes.m
src/video/cocoa/SDL_cocoavideo.m
--- a/src/video/cocoa/SDL_cocoaevents.m	Tue Feb 05 12:10:54 2013 -0800
+++ b/src/video/cocoa/SDL_cocoaevents.m	Fri Feb 08 00:54:08 2013 -0800
@@ -107,6 +107,7 @@
     [menuItem setSubmenu:serviceMenu];
 
     [NSApp setServicesMenu:serviceMenu];
+    [serviceMenu release];
 
     [appleMenu addItem:[NSMenuItem separatorItem]];
 
--- a/src/video/cocoa/SDL_cocoamessagebox.m	Tue Feb 05 12:10:54 2013 -0800
+++ b/src/video/cocoa/SDL_cocoamessagebox.m	Fri Feb 08 00:54:08 2013 -0800
@@ -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) {
--- a/src/video/cocoa/SDL_cocoamodes.m	Tue Feb 05 12:10:54 2013 -0800
+++ b/src/video/cocoa/SDL_cocoamodes.m	Fri Feb 08 00:54:08 2013 -0800
@@ -225,11 +225,13 @@
 {
     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 @@
             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 @@
             display.current_mode = mode;
             display.driverdata = displaydata;
             SDL_AddVideoDisplay(&display);
+            if (display.name) SDL_free(display.name);
         }
     }
     SDL_stack_free(displays);
--- a/src/video/cocoa/SDL_cocoavideo.m	Tue Feb 05 12:10:54 2013 -0800
+++ b/src/video/cocoa/SDL_cocoavideo.m	Fri Feb 08 00:54:08 2013 -0800
@@ -273,6 +273,7 @@
         [alert addButtonWithTitle:@"Ignore"];
         [alert addButtonWithTitle:@"Always Ignore"];
         const NSInteger clicked = [alert runModal];
+        [alert release];
 
         if (!initialized) {
             SDL_QuitSubSystem(SDL_INIT_VIDEO);