From 1c0c90323cce31cf0125eae8de8ade067f7fb1b3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 21 Nov 2017 21:30:47 -0800 Subject: [PATCH] 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index c8c0322fde234..57cc659482aa8 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -354,7 +354,9 @@ SDL_DisplayMode mode; if (GetDisplayMode(_this, moderef, link, &mode)) { CGDisplayModeRetain(moderef); - SDL_AddDisplayMode(display, &mode); + if (!SDL_AddDisplayMode(display, &mode)) { + SDL_free(mode.driverdata); + } } }