Skip to content

Commit

Permalink
Fixed bug 4986 - Memory leak in HIDAPI_JoystickConnected
Browse files Browse the repository at this point in the history
meyraud705

Memory allocated for device->joysticks on line 589 of SDL_hidapijoystick.c is never freed.

Also, use memmove because memory is overlapping.
  • Loading branch information
slouken committed Feb 15, 2020
1 parent f4e2355 commit 715f8d4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/joystick/hidapi/SDL_hidapijoystick.c
Expand Up @@ -616,9 +616,13 @@ HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID
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;
--SDL_HIDAPI_numjoysticks;
if (device->num_joysticks == 0) {
SDL_free(device->joysticks);
device->joysticks = NULL;
}

if (!shutting_down) {
SDL_PrivateJoystickRemoved(joystickID);
Expand Down

0 comments on commit 715f8d4

Please sign in to comment.