diff -r 74ac66d0e8ca src/joystick/SDL_joystick.c --- a/src/joystick/SDL_joystick.c Mon Oct 21 10:20:25 2019 +0300 +++ b/src/joystick/SDL_joystick.c Mon Oct 21 12:57:35 2019 +0200 @@ -1018,7 +1018,7 @@ SDL_JoystickUpdate(void) { int i; - SDL_Joystick *joystick; + SDL_Joystick *joystick, *next; if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { return; @@ -1074,7 +1074,8 @@ SDL_updating_joystick = SDL_FALSE; /* 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) { SDL_JoystickClose(joystick); }