We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5042

Summary: Memory leak in SDL_xinputjoystick minimal example program
Product: SDL Reporter: sdlbugs
Component: joystickAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: 2.0.10   
Hardware: x86   
OS: Windows 10   
Attachments: Diff for fixing leak in SDL2-2.0.12

Description sdlbugs 2020-03-17 09:47:54 UTC
Created attachment 4265 [details]
Diff for fixing leak in SDL2-2.0.12

Several memory leaks noted in SDL_xinputjoystick.c when the following program run on a Windows machine:

#include "SDL.h"
 
int main()
{
    SDL_SetMainReady();
    SDL_Init(SDL_INIT_GAMECONTROLLER);
    SDL_Quit();

    return 0;
}

I don't remember spotting these in 2.0.10, but they're there in 2.0.12.  Reported as 2.0.10 though because 2.0.12 isn't an option at this time.

Attached a patch that fixes them. Problems were:

- GuessXInputDevice() does not delete dynamically allocated local member 'devices' on all return paths.
- SDL_XINPUT_JoystickQuit() does not delete static device info, so name strings leak.

I also added (redundant) array initialisation code to s_arrXInputDevicePath[] to make it extra, extra clear that it needs to be null'd before use.
Comment 1 sdlbugs 2020-03-17 10:53:38 UTC
Note, you might need a controller plugged in to cause the leak