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 5375

Summary: [PATCH] WGI: Fix HSTRING memory leak.
Product: SDL Reporter: Joel Linn <jl>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.13   
Hardware: All   
OS: Windows 10   
Attachments: Release the HSTRING to fix memleak.

Description Joel Linn 2020-12-01 23:49:42 UTC
Created attachment 4551 [details]
Release the HSTRING to fix memleak.

I might be wrong about this one since the documentation on the WinRT C interface is pretty much non-existent.

However I am pretty certain the property-getter transfers ownership of the HSTRING to the caller or rather increments the reference count. Anyways, we shall release the HSTRING.
Comment 1 Sam Lantinga 2020-12-09 14:28:36 UTC
I'm not sure about this one, so I'm going to wait to include it until after 2.0.14 release.
Comment 2 Joel Linn 2020-12-09 23:31:38 UTC
TLDR; https://godbolt.org/z/43fd8G

Let's deduce this from C++ reference code:

https://docs.microsoft.com/en-us/cpp/cppcx/wrl/how-to-activate-and-use-a-windows-runtime-component-using-wrl?view=msvc-160
At the bottom of the page there is this snippet:
```
int wmain()
{
    /* ... more code ... */

    // Get the domain part of the URI.
    HString domainName;
    hr = uri->get_Domain(domainName.GetAddressOf());
    if (FAILED(hr))
    {
        return PrintError(__LINE__, hr);
    }

    // Print the domain name and return.
    wprintf_s(L"Domain name: %s\n", domainName.GetRawBuffer(nullptr));

    // All smart pointers and RAII objects go out of scope here.
}
```

`HString` is defined in `corewrappers.h` and the call chain for the destructor is:
`~HString() -> Release() -> ::WindowsDeleteString()`

QED
Comment 3 Sam Lantinga 2020-12-10 04:29:24 UTC
Sold!
https://hg.libsdl.org/SDL/rev/e4681c33144e

Thanks for researching this. :)