mirror of https://github.com/encounter/SDL.git
Fixed crash if allocating memory for game controller failed.
This commit is contained in:
parent
8000e6d9e1
commit
af26379881
|
@ -1205,8 +1205,27 @@ SDL_GameControllerOpen(int device_index)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gamecontroller->last_match_axis = (SDL_ExtendedGameControllerBind **)SDL_calloc(gamecontroller->joystick->naxes, sizeof(*gamecontroller->last_match_axis));
|
||||
gamecontroller->last_hat_mask = (Uint8 *)SDL_calloc(gamecontroller->joystick->nhats, sizeof(*gamecontroller->last_hat_mask));
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue