On Sun Nov 2 21:14:03 2025 +0000, Vibhav Pant wrote:
How about removing AddRef call from throw_exception helper? C++/CX code that manually throws exceptions is still compiled with a call to `AddRef` before `_CxxThrowException`. This just seems to be the code generated by MSVC for throwing exceptions in `C++/CX`, rather than something specific to the `__abi_WinRTraise*` functions. So even if we don't remove the AddRef call here, exceptions thrown from C++/CX code would still leak, I think. The [test code here](https://gitlab.winehq.org/wine/wine/-/snippets/31) suggests that not only there is a `__FINALLY` terminating handler that does call Release, but also that `__CxxFrameHandler(4)` calls `Release` before it dispatches the object to a matching `catch`. We could probably replace `IUnknown_Release` with `IUnknown_AddRef` in `copy_exception` to get the same results. That way, with the additional `Release/__DestructExceptionObject` in `_C_specific_handler`, the exception should be correctly freed. I create a draft !9351 which tries to call the exception destructor in `__C_specific_handler`, and call `Release` for WinRT exceptions in `copy_exception`. It's likely not what all native is doing for C++/WinRT exceptions, but it does resolve the leaks.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/9209#note_120473