From 22fb9edd5c30a45f5133e7f2c5ded18c8b3d3b2d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 27 May 2026 11:43:57 -0400 Subject: [PATCH] x11: SetupWindowData shouldn't add to videodata->windowlist until success. Fixes #15676. --- src/video/x11/SDL_x11window.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index a0864d71b4..f7befe07f9 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -374,9 +374,6 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w SDL_VideoData *videodata = _this->internal; SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); SDL_WindowData *data; - int numwindows = videodata->numwindows; - int windowlistlength = videodata->windowlistlength; - SDL_WindowData **windowlist = videodata->windowlist; // Allocate the window data data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); @@ -392,19 +389,13 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w // Associate the data with the window - if (numwindows < windowlistlength) { - windowlist[numwindows] = data; - videodata->numwindows++; - } else { - SDL_WindowData ** new_windowlist = (SDL_WindowData **)SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); + if (videodata->numwindows >= videodata->windowlistlength) { + SDL_WindowData ** new_windowlist = (SDL_WindowData **)SDL_realloc(videodata->windowlist, (videodata->numwindows + 1) * sizeof(*videodata->windowlist)); if (!new_windowlist) { goto error_cleanup; } - windowlist = new_windowlist; - windowlist[numwindows] = data; - videodata->numwindows++; videodata->windowlistlength++; - videodata->windowlist = windowlist; + videodata->windowlist = new_windowlist; } // Fill in the SDL window with the window data @@ -487,6 +478,7 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w // All done! window->internal = data; + videodata->windowlist[videodata->numwindows++] = data; return true; error_cleanup: