X11: Fixed a memory leak when adding duplicate display modes.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 07 Aug 2015 00:59:31 -0400
changeset 9832 5fa8cf552d05
parent 9831 6c7e2f0747f7
child 9833 c3214bb33a1d
X11: Fixed a memory leak when adding duplicate display modes.
src/video/x11/SDL_x11modes.c
--- a/src/video/x11/SDL_x11modes.c	Wed Aug 05 21:04:10 2015 +0200
+++ b/src/video/x11/SDL_x11modes.c	Fri Aug 07 00:59:31 2015 -0400
@@ -748,7 +748,9 @@
                 *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
             }
             mode.driverdata = modedata;
-            SDL_AddDisplayMode(sdl_display, &mode);
+            if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+                SDL_free(modedata);
+            }
         }
         else if (!data->use_xrandr)
         {
@@ -762,7 +764,9 @@
                 *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
             }
             mode.driverdata = modedata;
-            SDL_AddDisplayMode(sdl_display, &mode);
+            if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+                SDL_free(modedata);
+            }
         }
 
     }
@@ -787,9 +791,8 @@
                     }
                     mode.driverdata = modedata;
 
-                    if (SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode)) {
-                        SDL_AddDisplayMode(sdl_display, &mode);
-                    } else {
+                    if (!SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode) ||
+                        !SDL_AddDisplayMode(sdl_display, &mode)) {
                         SDL_free(modedata);
                     }
                 }
@@ -822,9 +825,7 @@
             }
             mode.driverdata = modedata;
 
-            if (SetXVidModeModeInfo(modes[i], &mode)) {
-                SDL_AddDisplayMode(sdl_display, &mode);
-            } else {
+            if (!SetXVidModeModeInfo(modes[i], &mode) || !SDL_AddDisplayMode(sdl_display, &mode)) {
                 SDL_free(modedata);
             }
         }
@@ -842,7 +843,9 @@
             *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
         }
         mode.driverdata = modedata;
-        SDL_AddDisplayMode(sdl_display, &mode);
+        if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+            SDL_free(modedata);
+        }
     }
 }