MinGW implementation of Microsoft::WRL::ComPtr::Attach leaks references.
https://docs.microsoft.com/en-us/cpp/cppcx/wrl/comptr-class?view=msvc-160#attach is not specific, but https://github.com/microsoft/DirectX-Headers/blob/2620a5ca8af6cb524f0ee77ffb9195edbc12be98/include/wsl/wrladapter.h#L293-L305 clearly shows that ComPtr should assume the given COM object pointer without increasing its reference count. But that's not what MinGW implementation does.
I've attached a test case.
I think the fix should be trivial, something like
diff --git a/mingw-w64-headers/include/wrl/client.h b/mingw-w64-headers/include/wrl/client.h index 12239e108..aeb886ea8 100644 --- a/mingw-w64-headers/include/wrl/client.h +++ b/mingw-w64-headers/include/wrl/client.h @@ -206,7 +206,6 @@ namespace Microsoft { if (ptr_ != other) { InternalRelease(); ptr_ = other; - InternalAddRef(); } }
Detach implementation looks alright AFAICS.
https://github.com/Microsoft/DirectXTK/wiki/ComPtr#constructing-assigning-and-copying-comptr also makes this explicit. It says: