Commit ac1f174ad5d27bb2626dd7c2d8e65a7dbc1a0a62

Sam Lantinga 2020-06-02T17:02:37

Fixed bug 5167 - Memory leak in GuessXInputDevice meyraud705 Variable 'devices' is not freed if function GuessXInputDevice, in SDL_xinputjoystick.c, return early.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c
index 5bedc4b..72fa439 100644
--- a/src/joystick/windows/SDL_xinputjoystick.c
+++ b/src/joystick/windows/SDL_xinputjoystick.c
@@ -155,6 +155,7 @@ GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion)
                     *pVID = (Uint16)rdi.hid.dwVendorId;
                     *pPID = (Uint16)rdi.hid.dwProductId;
                     *pVersion = (Uint16)rdi.hid.dwVersionNumber;
+                    SDL_free(devices);
                     return;
                 }
             }
@@ -201,6 +202,7 @@ GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion)
                     SDL_free(s_arrXInputDevicePath[userid]);
                 }
                 s_arrXInputDevicePath[userid] = SDL_strdup(devName);
+                SDL_free(devices);
                 return;
             }
         }