From 845212388e74ebfaf28ac1728cd182bfa6010e05 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 25 Aug 2024 11:05:40 +0300
Subject: [PATCH] RAWINPUT_JoystickOpen: add missing SDL_stack_free() calls.
Fixes https://github.com/libsdl-org/SDL/issues/10574.
---
src/joystick/windows/SDL_rawinputjoystick.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 4b0213c0b8a13..55b7769ab82a4 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1294,6 +1294,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");
}
@@ -1322,6 +1323,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 -1;
}
@@ -1346,6 +1349,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];
@@ -1375,6 +1380,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 -1;
}
@@ -1408,6 +1414,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 -1;
}
@@ -1426,6 +1433,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
+ SDL_stack_free(value_caps);
+
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
if (ctx->is_xinput) {
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true);