Browse Source

wayland: Ensure that a NULL internal structure isn't dereferenced when destroying a window

In some cases, such as when recreating a window during renderer initialization, a failure can leave the window in a state where the internal structure has already been freed, but the higher level window object needs to be destroyed separately. Check that the internal handle is valid before attempting to access any data during destruction.

Allows for graceful failure instead of a crash during cleanup if renderer creation fails.
Frank Praznik 7 months ago
parent
commit
6d92de5d3a
1 changed files with 7 additions and 6 deletions
  1. 7 6
      src/video/wayland/SDL_waylandwindow.c

+ 7 - 6
src/video/wayland/SDL_waylandwindow.c

@@ -2818,13 +2818,14 @@ void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
     SDL_VideoData *data = _this->internal;
     SDL_WindowData *wind = window->internal;
 
-    /* Roundtrip before destroying the window to make sure that it has received input leave events, so that
-     * no internal structures are left pointing to the destroyed window. */
-    if (wind->show_hide_sync_required) {
-        WAYLAND_wl_display_roundtrip(data->display);
-    }
-
     if (data && wind) {
+        /* Roundtrip before destroying the window to make sure that it has received input leave events, so that
+         * no internal structures are left pointing to the destroyed window.
+         */
+        if (wind->show_hide_sync_required) {
+            WAYLAND_wl_display_roundtrip(data->display);
+        }
+
 #ifdef SDL_VIDEO_OPENGL_EGL
         if (wind->egl_surface) {
             SDL_EGL_DestroySurface(_this, wind->egl_surface);