-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaks SDL_stack_alloc/SDL_stack_free #10574
Milestone
Comments
Feel free to make a PR! |
If the issue is only in For SDL3: diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 4b0213c..24422e7 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;
}
@@ -1369,12 +1372,15 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes += 1;
}
+ SDL_stack_free(button_caps);
+
if (joystick->naxes > 0) {
int axis_index = 0;
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); For SDL2: diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 2e10708..9f9d3f2 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -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");
}
@@ -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();
}
@@ -1365,12 +1368,15 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes += 1;
}
+ SDL_stack_free(button_caps);
+
if (joystick->naxes > 0) {
int axis_index = 0;
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();
}
@@ -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();
}
@@ -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; |
This patch looks correct from here. |
OK, patch applied to all active branches and pushed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not all calls to SDL_stack_alloc have a corresponding SDL_stack_free. This causes memory leaks if SDL_DISABLE_ALLOCA is defined.
(See RAWINPUT_JoystickOpen).
The text was updated successfully, but these errors were encountered: