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 - [PATCH] WGI: Fix HSTRING memory leak.
Summary: [PATCH] WGI: Fix HSTRING memory leak.
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.13
Hardware: All Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-01 23:49 UTC by Joel Linn
Modified: 2020-12-10 04:29 UTC (History)
0 users

See Also:


Attachments
Release the HSTRING to fix memleak. (2.46 KB, patch)
2020-12-01 23:49 UTC, Joel Linn
Details | Diff

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