Commit 990990b4 by Rafael Cintron Committed by Commit Bot

Fix memory leak in Renderer11::getD3DTextureInfo

If the device for the texture does not match mDevice, we early out of the method without releasing textureDevice. Fixed by adding DynamicCastComObjectToComPtr and using angle::ComPtr Bug: angleproject:3761 Change-Id: Id4ef9231f8a91c30e326520132af693d51047c7d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1730175 Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 74e7a315
...@@ -1238,30 +1238,28 @@ NativeWindowD3D *Renderer11::createNativeWindow(EGLNativeWindowType window, ...@@ -1238,30 +1238,28 @@ NativeWindowD3D *Renderer11::createNativeWindow(EGLNativeWindowType window,
} }
egl::Error Renderer11::getD3DTextureInfo(const egl::Config *configuration, egl::Error Renderer11::getD3DTextureInfo(const egl::Config *configuration,
IUnknown *d3dTexture, IUnknown *texture,
EGLint *width, EGLint *width,
EGLint *height, EGLint *height,
EGLint *samples, EGLint *samples,
const angle::Format **angleFormat) const const angle::Format **angleFormat) const
{ {
ID3D11Texture2D *texture = d3d11::DynamicCastComObject<ID3D11Texture2D>(d3dTexture); angle::ComPtr<ID3D11Texture2D> d3dTexture =
if (texture == nullptr) d3d11::DynamicCastComObjectToComPtr<ID3D11Texture2D>(texture);
if (d3dTexture == nullptr)
{ {
return egl::EglBadParameter() << "client buffer is not a ID3D11Texture2D"; return egl::EglBadParameter() << "client buffer is not a ID3D11Texture2D";
} }
ID3D11Device *textureDevice = nullptr; angle::ComPtr<ID3D11Device> textureDevice;
texture->GetDevice(&textureDevice); d3dTexture->GetDevice(&textureDevice);
if (textureDevice != mDevice) if (textureDevice.Get() != mDevice)
{ {
SafeRelease(texture);
return egl::EglBadParameter() << "Texture's device does not match."; return egl::EglBadParameter() << "Texture's device does not match.";
} }
SafeRelease(textureDevice);
D3D11_TEXTURE2D_DESC desc = {0}; D3D11_TEXTURE2D_DESC desc = {0};
texture->GetDesc(&desc); d3dTexture->GetDesc(&desc);
SafeRelease(texture);
if (width) if (width)
{ {
......
...@@ -190,6 +190,21 @@ outType *DynamicCastComObject(IUnknown *object) ...@@ -190,6 +190,21 @@ outType *DynamicCastComObject(IUnknown *object)
} }
} }
template <typename outType>
angle::ComPtr<outType> DynamicCastComObjectToComPtr(IUnknown *object)
{
angle::ComPtr<outType> outObject;
const HRESULT hr = object->QueryInterface(IID_PPV_ARGS(&outObject));
if (SUCCEEDED(hr))
{
return outObject;
}
else
{
return nullptr;
}
}
inline bool isDeviceLostError(HRESULT errorCode) inline bool isDeviceLostError(HRESULT errorCode)
{ {
switch (errorCode) switch (errorCode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment