Fixed 2584 - Memory leak in Cocoa_GetDisplayName
authorSam Lantinga <slouken@libsdl.org>
Sun, 15 Jun 2014 17:18:05 -0700
changeset 886649562091afe1
parent 8865 105bbdd3183d
child 8867 540acbf32d5b
Fixed 2584 - Memory leak in Cocoa_GetDisplayName

Diego

The Xcode Instruments Leak tool reports a leak from IODisplayCreateInfoDictionary in Cocoa_GetDisplayName.
This happened after upgrading to Xcode 5.
src/video/cocoa/SDL_cocoamodes.m
     1.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Sun Jun 15 13:05:30 2014 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Sun Jun 15 17:18:05 2014 -0700
     1.3 @@ -200,14 +200,14 @@
     1.4  static const char *
     1.5  Cocoa_GetDisplayName(CGDirectDisplayID displayID)
     1.6  {
     1.7 -    NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
     1.8 -    NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
     1.9 +    CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
    1.10 +    NSDictionary *localizedNames = [(NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
    1.11      const char* displayName = NULL;
    1.12  
    1.13      if ([localizedNames count] > 0) {
    1.14          displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
    1.15      }
    1.16 -    [deviceInfo release];
    1.17 +    CFRelease(deviceInfo);
    1.18      return displayName;
    1.19  }
    1.20