Skip to content

Commit bc9888c

Browse files
committed
OS2_GetDisplayModes: malloc a new copy of mode's driver data.
Based on a patch by Jochen Schäfer <[email protected]> : The problem is, that in the initialization code uses the same structure for desktop_mode and current_mode. See SDL_os2video.c:OS2_VideoInit(): stSDLDisplay.desktop_mode = stSDLDisplayMode; stSDLDisplay.current_mode = stSDLDisplayMode; ... stSDLDisplayMode.driverdata = pDisplayData; Then, if you call GetDisplayModes, current_mode will added to the modes list, with the same driverdata pointer to desktop_mode. SDL_AddDisplayMode( display, &display->current_mode ); When VideoQuit gets called, first the modes list gets freed including the driverdata, the desktop_mode gets freed. See SDL_video.c:SDL_VideoQuit(): for (j = display->num_display_modes; j--;) { SDL_free(display->display_modes[j].driverdata); display->display_modes[j].driverdata = NULL; } SDL_free(display->display_modes); display->display_modes = NULL; SDL_free(display->desktop_mode.driverdata); display->desktop_mode.driverdata = NULL; So, the display_modes[j].driverdata gets freed, but desktop_mode->driverdata points to the same memory, but is not NULL'ed. When desktop_mode->driverdata gets freed the memory is already freed, and libcx crashes the application on SDL_Quit.
1 parent d28437d commit bc9888c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/video/os2/SDL_os2video.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,14 @@ static int OS2_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi,
15621562

15631563
static void OS2_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
15641564
{
1565+
SDL_DisplayMode mode;
1566+
15651567
debug_os2("Enter");
1566-
SDL_AddDisplayMode(display, &display->current_mode);
1568+
SDL_memcpy(&mode, &display->current_mode, sizeof(SDL_DisplayMode));
1569+
mode.driverdata = (MODEDATA *) SDL_malloc(sizeof(MODEDATA));
1570+
if (!mode.driverdata) return; /* yikes.. */
1571+
SDL_memcpy(mode.driverdata, display->current_mode.driverdata, sizeof(MODEDATA));
1572+
SDL_AddDisplayMode(display, &mode);
15671573
}
15681574

15691575
static int OS2_SetDisplayMode(_THIS, SDL_VideoDisplay *display,

0 commit comments

Comments
 (0)