Skip to content

Commit

Permalink
RAWINPUT_JoystickOpen: add missing SDL_stack_free() calls.
Browse files Browse the repository at this point in the history
Fixes #10574.
(cherry picked from commit 8452123)
(cherry picked from commit 4eac44b)
  • Loading branch information
sezero committed Aug 25, 2024
1 parent 9481964 commit 00494df
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/joystick/windows/SDL_rawinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
value_caps = SDL_stack_alloc(HIDP_VALUE_CAPS, caps.NumberInputValueCaps);
if (SDL_HidP_GetValueCaps(HidP_Input, value_caps, &caps.NumberInputValueCaps, ctx->preparsed_data) != HIDP_STATUS_SUCCESS) {
RAWINPUT_JoystickClose(joystick);
SDL_stack_free(button_caps);
return SDL_SetError("Couldn't get device value capabilities");
}

Expand Down Expand Up @@ -1318,6 +1319,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->button_indices = (USHORT *)SDL_malloc(joystick->nbuttons * sizeof(*ctx->button_indices));
if (!ctx->button_indices) {
RAWINPUT_JoystickClose(joystick);
SDL_stack_free(value_caps);
SDL_stack_free(button_caps);
return SDL_OutOfMemory();
}

Expand All @@ -1342,6 +1345,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nbuttons += 1;
}

SDL_stack_free(button_caps);

for (i = 0; i < caps.NumberInputValueCaps; ++i) {
HIDP_VALUE_CAPS *cap = &value_caps[i];

Expand Down Expand Up @@ -1371,6 +1376,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->axis_indices = (USHORT *)SDL_malloc(joystick->naxes * sizeof(*ctx->axis_indices));
if (!ctx->axis_indices) {
RAWINPUT_JoystickClose(joystick);
SDL_stack_free(value_caps);
return SDL_OutOfMemory();
}

Expand Down Expand Up @@ -1404,6 +1410,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->hat_indices = (USHORT *)SDL_malloc(joystick->nhats * sizeof(*ctx->hat_indices));
if (!ctx->hat_indices) {
RAWINPUT_JoystickClose(joystick);
SDL_stack_free(value_caps);
return SDL_OutOfMemory();
}

Expand All @@ -1422,6 +1429,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}

SDL_stack_free(value_caps);

joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;

return 0;
Expand Down

0 comments on commit 00494df

Please sign in to comment.