From 6b4a7b19a417cbda07402997b5dd741d8d341363 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 1 Sep 2011 04:25:15 -0400 Subject: [PATCH] Clean up any opened joysticks during SDL_JoystickQuit(). Otherwise, these leak memory and maybe operating system handles. --- src/joystick/SDL_joystick.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 64afb9d15..83c07a29e 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -403,9 +403,22 @@ SDL_JoystickClose(SDL_Joystick * joystick) void SDL_JoystickQuit(void) { + const int numsticks = SDL_numjoysticks; + int i; + /* Stop the event polling */ SDL_numjoysticks = 0; + SDL_assert( (SDL_joysticks == NULL) == (numsticks == 0) ); + + for (i = 0; i < numsticks; i++) { + SDL_Joystick *stick = SDL_joysticks[i]; + if (stick && (stick->ref_count >= 1)) { + stick->ref_count = 1; + SDL_JoystickClose(stick); + } + } + /* Quit the joystick setup */ SDL_SYS_JoystickQuit(); if (SDL_joysticks) {