Commit eea0b0e088303404c658990bb994295fa7c34267

Sam Lantinga 2020-06-02T17:08:31

Fixed bug 5168 - Memory leak in RAWINPUT_JoystickOpen meyraud705 Variable 'hwdata' is not freed in RAWINPUT_JoystickOpen if device->driver->OpenJoystick() fails.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 4134e4c..9d752bf 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -592,8 +592,8 @@ RAWINPUT_JoystickOpen(SDL_Joystick * joystick, int device_index)
     }
 
     if (!device->driver->OpenJoystick(&device->hiddevice, joystick)) {
-        /* Only possible error is out of memory */
-        return SDL_OutOfMemory();
+        SDL_free(hwdata);
+        return -1;
     }
 
     hwdata->reserved = (void*)-1; /* crash if some code slips by that tries to use this */