[PATCH 5/7] ddraw/tests: Avoid reference leaks in render-target tests.
Jeff Smith
whydoubt at gmail.com
Thu Dec 12 23:00:06 CST 2019
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
dlls/ddraw/tests/ddraw1.c | 7 ++++++-
dlls/ddraw/tests/ddraw2.c | 28 +++++++++++++++++-----------
dlls/ddraw/tests/ddraw4.c | 28 +++++++++++++++++-----------
dlls/ddraw/tests/ddraw7.c | 23 ++++++++++++-----------
4 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 66b84edf45..8407290259 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -4103,11 +4103,15 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
{
hr = IDirectDrawSurface_SetPalette(surface, palette);
ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
+ refcount = IDirectDrawPalette_AddRef(palette) - 1;
hr = IDirectDrawSurface_QueryInterface(surface, riid, (void **)&device);
if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
else
ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ /* If QueryInterface is successful, it adds multiple references to palette,
+ * none of which are released by IDirect3DDevice_Release. */
+ while (IDirectDrawPalette_Release(palette) > refcount) ;
}
if (SUCCEEDED(hr))
{
@@ -4120,7 +4124,8 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
device_name, i, refcount);
}
- IDirectDrawPalette_Release(palette);
+ refcount = IDirectDrawPalette_Release(palette);
+ ok(refcount == 0, "The palette object was not properly freed, refcount %u.\n", refcount);
refcount = IDirectDraw_Release(ddraw);
ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
DestroyWindow(window);
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 2bd56b7afd..0fc8e1859e 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -4546,18 +4546,23 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
hr = IDirect3D2_CreateDevice(d3d, riid, surface, &device);
ok(hr == test_data[i].create_device_hr, "Test %s %u: Got unexpected hr %#x, expected %#x.\n",
device_name, i, hr, test_data[i].create_device_hr);
+ if (hr == DDERR_NOPALETTEATTACHED)
+ {
+ hr = IDirectDrawSurface_SetPalette(surface, palette);
+ ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
+ refcount = IDirectDrawPalette_AddRef(palette);
+ hr = IDirect3D2_CreateDevice(d3d, riid, surface, &device);
+ if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
+ ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ else
+ ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ /* If CreateDevice is successful, it adds multiple references to palette,
+ * only one of which is released by IDirect3DDevice2_Release. */
+ if (FAILED(hr)) refcount--;
+ while (IDirectDrawPalette_Release(palette) > refcount) ;
+ }
if (FAILED(hr))
{
- if (hr == DDERR_NOPALETTEATTACHED)
- {
- hr = IDirectDrawSurface_SetPalette(surface, palette);
- ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
- hr = IDirect3D2_CreateDevice(d3d, riid, surface, &device);
- if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
- ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- else
- ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- }
IDirectDrawSurface_Release(surface);
memset(&surface_desc, 0, sizeof(surface_desc));
@@ -4623,7 +4628,8 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
device_name, i, refcount);
}
- IDirectDrawPalette_Release(palette);
+ refcount = IDirectDrawPalette_Release(palette);
+ ok(refcount == 0, "The palette object was not properly freed, refcount %u.\n", refcount);
IDirect3D2_Release(d3d);
done:
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 0ab8c74dab..2df735abea 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -6158,18 +6158,23 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
hr = IDirect3D3_CreateDevice(d3d, riid, surface, &device, NULL);
ok(hr == test_data[i].create_device_hr, "Test %s %u: Got unexpected hr %#x, expected %#x.\n",
device_name, i, hr, test_data[i].create_device_hr);
+ if (hr == DDERR_NOPALETTEATTACHED)
+ {
+ hr = IDirectDrawSurface4_SetPalette(surface, palette);
+ ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
+ refcount = IDirectDrawPalette_AddRef(palette);
+ hr = IDirect3D3_CreateDevice(d3d, riid, surface, &device, NULL);
+ if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
+ ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ else
+ ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ /* If CreateDevice is successful, it adds multiple references to palette,
+ * only one of which is released by IDirect3DDevice3_Release. */
+ if (FAILED(hr)) refcount--;
+ while (IDirectDrawPalette_Release(palette) > refcount) ;
+ }
if (FAILED(hr))
{
- if (hr == DDERR_NOPALETTEATTACHED)
- {
- hr = IDirectDrawSurface4_SetPalette(surface, palette);
- ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
- hr = IDirect3D3_CreateDevice(d3d, riid, surface, &device, NULL);
- if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
- ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- else
- ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- }
IDirectDrawSurface4_Release(surface);
memset(&surface_desc, 0, sizeof(surface_desc));
@@ -6224,7 +6229,8 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
device_name, i, refcount);
}
- IDirectDrawPalette_Release(palette);
+ refcount = IDirectDrawPalette_Release(palette);
+ ok(refcount == 0, "The palette object was not properly freed, refcount %u.\n", refcount);
IDirect3D3_Release(d3d);
done:
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index f2552ad491..7a073296ca 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -5905,18 +5905,18 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
hr = IDirect3D7_CreateDevice(d3d, riid, surface, &device);
ok(hr == test_data[i].create_device_hr, "Test %s %u: Got unexpected hr %#x, expected %#x.\n",
device_name, i, hr, test_data[i].create_device_hr);
+ if (hr == DDERR_NOPALETTEATTACHED)
+ {
+ hr = IDirectDrawSurface7_SetPalette(surface, palette);
+ ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
+ hr = IDirect3D7_CreateDevice(d3d, riid, surface, &device);
+ if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
+ ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ else
+ ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
+ }
if (FAILED(hr))
{
- if (hr == DDERR_NOPALETTEATTACHED)
- {
- hr = IDirectDrawSurface7_SetPalette(surface, palette);
- ok(SUCCEEDED(hr), "Test %s %u: Failed to set palette, hr %#x.\n", device_name, i, hr);
- hr = IDirect3D7_CreateDevice(d3d, riid, surface, &device);
- if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
- ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- else
- ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %s %u: Got unexpected hr %#x.\n", device_name, i, hr);
- }
IDirectDrawSurface7_Release(surface);
memset(&surface_desc, 0, sizeof(surface_desc));
@@ -5972,7 +5972,8 @@ static void test_rt_caps_riid(REFCLSID riid, const char *device_name)
device_name, i, refcount);
}
- IDirectDrawPalette_Release(palette);
+ refcount = IDirectDrawPalette_Release(palette);
+ ok(refcount == 0, "The palette object was not properly freed, refcount %u.\n", refcount);
IDirect3D7_Release(d3d);
done:
--
2.23.0
More information about the wine-devel
mailing list