Commit cd930cf0 by Jamie Madill Committed by Commit Bot

EGLDevice: Fix edge-case memory leak.

This could happen if there was an error on device init. Reported by Microsoft. BUG=None Change-Id: I059fd9308d0536b4120c28e684e37567d14b3fd5 Reviewed-on: https://chromium-review.googlesource.com/519642 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent e0cff190
...@@ -45,25 +45,20 @@ static DeviceSet *GetDeviceSet() ...@@ -45,25 +45,20 @@ static DeviceSet *GetDeviceSet()
// Static factory methods // Static factory methods
egl::Error Device::CreateDevice(void *devicePointer, EGLint deviceType, Device **outDevice) egl::Error Device::CreateDevice(void *devicePointer, EGLint deviceType, Device **outDevice)
{ {
*outDevice = nullptr;
#if defined(ANGLE_ENABLE_D3D11) #if defined(ANGLE_ENABLE_D3D11)
if (deviceType == EGL_D3D11_DEVICE_ANGLE) if (deviceType == EGL_D3D11_DEVICE_ANGLE)
{ {
rx::DeviceD3D *deviceD3D = new rx::DeviceD3D(); std::unique_ptr<rx::DeviceD3D> deviceD3D(new rx::DeviceD3D());
egl::Error error = deviceD3D->initialize(devicePointer, deviceType, EGL_TRUE); ANGLE_TRY(deviceD3D->initialize(devicePointer, deviceType, EGL_TRUE));
if (error.isError()) *outDevice = new Device(nullptr, deviceD3D.release());
{
*outDevice = nullptr;
return error;
}
*outDevice = new Device(nullptr, deviceD3D);
GetDeviceSet()->insert(*outDevice); GetDeviceSet()->insert(*outDevice);
return egl::Error(EGL_SUCCESS); return egl::NoError();
} }
#endif #endif
// Note that creating an EGL device from inputted D3D9 parameters isn't currently supported // Note that creating an EGL device from inputted D3D9 parameters isn't currently supported
*outDevice = nullptr;
return egl::Error(EGL_BAD_ATTRIBUTE); return egl::Error(EGL_BAD_ATTRIBUTE);
} }
......
...@@ -56,12 +56,8 @@ egl::Error DeviceD3D::initialize(void *device, ...@@ -56,12 +56,8 @@ egl::Error DeviceD3D::initialize(void *device,
return egl::Error(EGL_BAD_DEVICE_EXT); return egl::Error(EGL_BAD_DEVICE_EXT);
} }
mDevice = device;
mDeviceType = deviceType;
mDeviceExternallySourced = !!deviceExternallySourced;
#if defined(ANGLE_ENABLE_D3D11) #if defined(ANGLE_ENABLE_D3D11)
if (mDeviceType == EGL_D3D11_DEVICE_ANGLE) if (deviceType == EGL_D3D11_DEVICE_ANGLE)
{ {
// Validate the device // Validate the device
IUnknown *iunknown = reinterpret_cast<IUnknown *>(device); IUnknown *iunknown = reinterpret_cast<IUnknown *>(device);
...@@ -81,10 +77,13 @@ egl::Error DeviceD3D::initialize(void *device, ...@@ -81,10 +77,13 @@ egl::Error DeviceD3D::initialize(void *device,
else else
#endif #endif
{ {
ASSERT(!mDeviceExternallySourced); ASSERT(deviceExternallySourced == EGL_FALSE);
} }
mIsInitialized = true; mDevice = device;
mDeviceType = deviceType;
mDeviceExternallySourced = !!deviceExternallySourced;
mIsInitialized = true;
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
......
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