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 - Memory leak in SDL_xinputjoystick minimal example program
Summary: Memory leak in SDL_xinputjoystick minimal example program
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.10
Hardware: x86 Windows 10
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-17 09:47 UTC by sdlbugs
Modified: 2020-03-17 10:53 UTC (History)
0 users

See Also:


Attachments
Diff for fixing leak in SDL2-2.0.12 (1.82 KB, patch)
2020-03-17 09:47 UTC, sdlbugs
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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