Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed crash if allocating memory for game controller failed.
  • Loading branch information
philippwiesemann committed Dec 28, 2016
1 parent 8000e6d commit af26379
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -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);

Expand Down

0 comments on commit af26379

Please sign in to comment.