Fixed bug 3976 - SDL drivers may leak driverdata memory due to ignoring return value of SDL_AddDisplayMode
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Nov 2017 21:30:47 -0800
changeset 1171053049fd16008
parent 11709 cef120429a95
child 11711 8a982ed61896
Fixed bug 3976 - SDL drivers may leak driverdata memory due to ignoring return value of SDL_AddDisplayMode

C Snover

SDL_AddDisplayMode returns an SDL_bool corresponding to whether or not the given display mode was added or not. It will return SDL_FALSE if a matching display mode already exists in the display's list of display modes, which causes ownership of the mode driverdata to remain with the caller. Some video drivers ignore the return value of SDL_AddDisplayMode, so leak the driverdata memory when SDL_AddDisplayMode returns SDL_FALSE.
src/video/cocoa/SDL_cocoamodes.m
     1.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Mon Nov 20 13:59:43 2017 -0500
     1.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Tue Nov 21 21:30:47 2017 -0800
     1.3 @@ -354,7 +354,9 @@
     1.4              SDL_DisplayMode mode;
     1.5              if (GetDisplayMode(_this, moderef, link, &mode)) {
     1.6                  CGDisplayModeRetain(moderef);
     1.7 -                SDL_AddDisplayMode(display, &mode);
     1.8 +                if (!SDL_AddDisplayMode(display, &mode)) {
     1.9 +                    SDL_free(mode.driverdata);
    1.10 +                }
    1.11              }
    1.12          }
    1.13