| Summary: | [PATCH] WGI: Fix HSTRING memory leak. | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Joel Linn <jl> |
| Component: | joystick | Assignee: | 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. | ||
I'm not sure about this one, so I'm going to wait to include it until after 2.0.14 release. 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 Sold! https://hg.libsdl.org/SDL/rev/e4681c33144e Thanks for researching this. :) |
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.