SDL: Fix leak in SDL_GameControllerTypeForIndex() (6e5ca)

From 6e5cad8e1eb46b4c0197aeebd28b5d4761b3d4d1 Mon Sep 17 00:00:00 2001
From: Petar Popovic <[EMAIL REDACTED]>
Date: Sat, 1 Nov 2025 15:14:30 +0100
Subject: [PATCH] Fix leak in SDL_GameControllerTypeForIndex()

(cherry picked from commit 398bacbac3ee8cb5572a783db850845519b41d9f)
---
 src/joystick/SDL_gamecontroller.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 36e521eb956dc..adc8dd3e88e69 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -1984,7 +1984,7 @@ const char *SDL_GameControllerPathForIndex(int joystick_index)
 SDL_GameControllerType SDL_GameControllerTypeForIndex(int joystick_index)
 {
     SDL_JoystickGUID joystick_guid = SDL_JoystickGetDeviceGUID(joystick_index);
-    const char *mapping = SDL_GameControllerMappingForGUID(joystick_guid);
+    char *mapping = SDL_GameControllerMappingForGUID(joystick_guid);
     char *type_string, *comma;
     SDL_GameControllerType type;
     if (mapping) {
@@ -1999,8 +1999,10 @@ SDL_GameControllerType SDL_GameControllerTypeForIndex(int joystick_index)
             } else {
                 type = SDL_GetGameControllerTypeFromString(type_string);
             }
+            SDL_free(mapping);
             return type;
         }
+        SDL_free(mapping);
     }
     return SDL_GetJoystickGameControllerTypeFromGUID(joystick_guid, SDL_JoystickNameForIndex(joystick_index));
 }