[Commits] SDL: Clean up any opened joysticks during SDL_JoystickQuit().

libsdl.org revision control commits-owner at libsdl.org
Thu Sep 1 01:26:32 PDT 2011


details:   http://hg.libsdl.org/SDL/rev/173d28fd4be4
changeset: 5856:173d28fd4be4
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Thu Sep 01 04:25:15 2011 -0400
description:
Clean up any opened joysticks during SDL_JoystickQuit().

Otherwise, these leak memory and maybe operating system handles.

diffstat:

 src/joystick/SDL_joystick.c |  13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diffs (26 lines):

diff -r bdfb7a2a86e1 -r 173d28fd4be4 src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Tue Aug 30 17:11:51 2011 -0400
+++ b/src/joystick/SDL_joystick.c	Thu Sep 01 04:25:15 2011 -0400
@@ -403,9 +403,22 @@
 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) {


More information about the commits mailing list