Fixed use after free (thanks @meyraud705!)

Fixes https://github.com/libsdl-org/SDL/issues/11090
This commit is contained in:
Sam Lantinga 2024-10-06 08:34:35 -07:00
parent e159bcf5de
commit 0f47d3a77b

View File

@ -47,7 +47,7 @@ SDL_COMPILE_TIME_ASSERT(cursorNames, SDL_arraysize(cursorNames) == SDL_SYSTEM_CU
static int system_cursor = -1;
static SDL_Cursor *cursor = NULL;
static const SDL_DisplayMode *highlighted_mode = NULL;
static SDL_DisplayMode highlighted_mode;
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
static void
@ -95,7 +95,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
/* Clear the cached mode under the mouse */
if (window == SDL_GetMouseFocus()) {
highlighted_mode = NULL;
SDL_zero(highlighted_mode);
}
displays = SDL_GetDisplays(NULL);
@ -126,7 +126,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
/* Update cached mode under the mouse */
if (window == SDL_GetMouseFocus()) {
highlighted_mode = mode;
SDL_copyp(&highlighted_mode, mode);
}
} else {
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
@ -213,9 +213,9 @@ static void loop(void)
}
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
SDL_Window *window = SDL_GetMouseFocus();
if (highlighted_mode && window) {
SDL_memcpy(&state->fullscreen_mode, highlighted_mode, sizeof(state->fullscreen_mode));
SDL_SetWindowFullscreenMode(window, highlighted_mode);
if (highlighted_mode.w && window) {
SDL_copyp(&state->fullscreen_mode, &highlighted_mode, sizeof(state->fullscreen_mode));
SDL_SetWindowFullscreenMode(window, &highlighted_mode);
}
}
}