X11: Fixed a memory leak when adding duplicate display modes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index 4a91f07..b184dd8 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -748,7 +748,9 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
*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 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
*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 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
}
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 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
}
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 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
*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);
+ }
}
}