Fixed bug 4838 - Use after free in SDL_JoystickUpdate (Thanks!)

This commit is contained in:
Sylvain Becker 2019-10-23 08:50:57 +02:00
parent 3ac67cf458
commit b7ab3b3984

View File

@ -1018,7 +1018,7 @@ void
SDL_JoystickUpdate(void) SDL_JoystickUpdate(void)
{ {
int i; int i;
SDL_Joystick *joystick; SDL_Joystick *joystick, *next;
if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { if (!SDL_WasInit(SDL_INIT_JOYSTICK)) {
return; return;
@ -1074,7 +1074,8 @@ SDL_JoystickUpdate(void)
SDL_updating_joystick = SDL_FALSE; SDL_updating_joystick = SDL_FALSE;
/* If any joysticks were closed while updating, free them here */ /* If any joysticks were closed while updating, free them here */
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) { for (joystick = SDL_joysticks; joystick; joystick = next) {
next = joystick->next;
if (joystick->ref_count <= 0) { if (joystick->ref_count <= 0) {
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
} }