SDL: Fixed wayland cursor use-after-free at shutdown

From b9d018f2a28b2bb70cc30d6d2351e2245bf48340 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 12 Feb 2025 20:47:31 -0800
Subject: [PATCH] Fixed wayland cursor use-after-free at shutdown

---
 src/video/wayland/SDL_waylandmouse.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index 968cb6f0ffdfe..8075c3a2d880f 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -598,6 +598,13 @@ static SDL_Cursor *Wayland_CreateDefaultCursor(void)
 
 static void Wayland_FreeCursorData(SDL_CursorData *d)
 {
+    SDL_VideoDevice *vd = SDL_GetVideoDevice();
+    struct SDL_WaylandInput *input = vd->internal->input;
+
+    if (input->current_cursor == d) {
+        input->current_cursor = NULL;
+    }
+
     // Buffers for system cursors must not be destroyed.
     if (d->is_system_cursor) {
         if (d->cursor_data.system.frame_callback) {