SDL: wayland: Fix double free when deleting an output display (31f77)

From 31f77182d0bab34b1e9f5bf0c69b8bc6e231d270 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Fri, 21 Jun 2024 12:59:21 -0400
Subject: [PATCH] wayland: Fix double free when deleting an output display

(cherry picked from commit 3b88d4f46f94e8adafc77ea0edd317b5e61d196c)
---
 src/video/wayland/SDL_waylandvideo.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 9b593cc917704..11f3695e385c1 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -751,12 +751,11 @@ static void Wayland_free_display(SDL_VideoData *d, uint32_t id)
                     }
                 }
             }
-            SDL_DelVideoDisplay(i);
             if (data->xdg_output) {
                 zxdg_output_v1_destroy(data->xdg_output);
             }
             wl_output_destroy(data->output);
-            SDL_free(data);
+            SDL_DelVideoDisplay(i);
 
             /* Update the index for all remaining displays */
             num_displays -= 1;
@@ -1016,9 +1015,6 @@ static void Wayland_VideoCleanup(_THIS)
         }
 
         wl_output_destroy(((SDL_WaylandOutputData *)display->driverdata)->output);
-        SDL_free(display->driverdata);
-        display->driverdata = NULL;
-
         SDL_DelVideoDisplay(i);
     }
     data->output_list = NULL;