mirror of https://github.com/encounter/SDL.git
Fixed bug 4986 - Memory leak in HIDAPI_JoystickConnected
meyraud705 Memory allocated for device->joysticks on line 589 of SDL_hidapijoystick.c is never freed. Also, use memmove because memory is overlapping.
This commit is contained in:
parent
f4e23553d7
commit
715f8d42a2
|
@ -616,9 +616,13 @@ HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID
|
||||||
HIDAPI_JoystickClose(joystick);
|
HIDAPI_JoystickClose(joystick);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_memcpy(&device->joysticks[i], &device->joysticks[i+1], device->num_joysticks - i - 1);
|
SDL_memmove(&device->joysticks[i], &device->joysticks[i+1], device->num_joysticks - i - 1);
|
||||||
--device->num_joysticks;
|
--device->num_joysticks;
|
||||||
--SDL_HIDAPI_numjoysticks;
|
--SDL_HIDAPI_numjoysticks;
|
||||||
|
if (device->num_joysticks == 0) {
|
||||||
|
SDL_free(device->joysticks);
|
||||||
|
device->joysticks = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!shutting_down) {
|
if (!shutting_down) {
|
||||||
SDL_PrivateJoystickRemoved(joystickID);
|
SDL_PrivateJoystickRemoved(joystickID);
|
||||||
|
|
Loading…
Reference in New Issue