SDL: wayland+x11: free system cursors when quiting video

From fbb0914b78bebfe83601a7b100f0d2ff5cf956c1 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 27 Nov 2023 21:30:59 +0100
Subject: [PATCH] wayland+x11: free system cursors when quiting video

---
 src/video/wayland/SDL_waylandmouse.c | 6 ++++++
 src/video/x11/SDL_x11mouse.c         | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index c670cdc18a13..11ab35cad30e 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -831,6 +831,7 @@ void Wayland_InitMouse(void)
 void Wayland_FiniMouse(SDL_VideoData *data)
 {
     struct SDL_WaylandInput *input = data->input;
+    int i;
 
     Wayland_FreeCursorThemes(data);
 
@@ -840,6 +841,11 @@ void Wayland_FiniMouse(SDL_VideoData *data)
 
     SDL_DelHintCallback(SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP,
                         Wayland_EmulateMouseWarpChanged, input);
+
+    for (i = 0; i < SDL_arraysize(sys_cursors); i++) {
+        Wayland_FreeCursor(sys_cursors[i]);
+        sys_cursors[i] = NULL;
+    }
 }
 
 void Wayland_SetHitTestCursor(SDL_HitTestResult rc)
diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c
index 9c32b12f80ba..a9199815202e 100644
--- a/src/video/x11/SDL_x11mouse.c
+++ b/src/video/x11/SDL_x11mouse.c
@@ -511,6 +511,12 @@ void X11_QuitMouse(SDL_VideoDevice *_this)
     SDL_VideoData *data = _this->driverdata;
     SDL_XInput2DeviceInfo *i;
     SDL_XInput2DeviceInfo *next;
+    int j;
+
+    for (j = 0; j < SDL_arraysize(sys_cursors); j++) {
+        X11_FreeCursor(sys_cursors[j]);
+        sys_cursors[j] = NULL;
+    }
 
     for (i = data->mouse_device_info; i; i = next) {
         next = i->next;