Fixed crash if allocating memory for game controller failed.

Philipp Wiesemann 2016-12-28 20:10:48 +01:00
parent 8000e6d9e1
commit af26379881
1 changed files with 21 additions and 2 deletions

View File

@ -1205,8 +1205,27 @@ SDL_GameControllerOpen(int device_index)
return NULL;
}
if (gamecontroller->joystick->naxes) {
gamecontroller->last_match_axis = (SDL_ExtendedGameControllerBind **)SDL_calloc(gamecontroller->joystick->naxes, sizeof(*gamecontroller->last_match_axis));
if (!gamecontroller->last_match_axis) {
SDL_OutOfMemory();
SDL_JoystickClose(gamecontroller->joystick);
SDL_free(gamecontroller);
SDL_UnlockJoystickList();
return NULL;
}
}
if (gamecontroller->joystick->nhats) {
gamecontroller->last_hat_mask = (Uint8 *)SDL_calloc(gamecontroller->joystick->nhats, sizeof(*gamecontroller->last_hat_mask));
if (!gamecontroller->last_hat_mask) {
SDL_OutOfMemory();
SDL_JoystickClose(gamecontroller->joystick);
SDL_free(gamecontroller->last_match_axis);
SDL_free(gamecontroller);
SDL_UnlockJoystickList();
return NULL;
}
}
SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);