From 91d2dbdc9dfe9c8751edfb69d9c40d7045c6b72e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 27 Jul 2024 13:44:45 -0700 Subject: [PATCH] Fixed memory leak if joysticks were initialized but gamepads were not If a joystick is connected, SDL_IsGamepad() will be called on it, which adds it to the cache, which then needs to be cleaned up when joysticks quit. --- src/joystick/SDL_gamepad.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 4dc94d7cf9..0d9648ab04 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -3686,11 +3686,6 @@ void SDL_QuitGamepads(void) SDL_CloseGamepad(SDL_gamepads); } - if (s_gamepadInstanceIDs) { - SDL_DestroyHashTable(s_gamepadInstanceIDs); - s_gamepadInstanceIDs = NULL; - } - SDL_UnlockJoysticks(); } @@ -3710,6 +3705,11 @@ void SDL_QuitGamepadMappings(void) SDL_FreeVIDPIDList(&SDL_allowed_gamepads); SDL_FreeVIDPIDList(&SDL_ignored_gamepads); + + if (s_gamepadInstanceIDs) { + SDL_DestroyHashTable(s_gamepadInstanceIDs); + s_gamepadInstanceIDs = NULL; + } } /*