Zhiyi Zhang : ddraw/tests: Fix possible memory leaks.
Alexandre Julliard
julliard at winehq.org
Wed Oct 21 15:15:14 CDT 2020
Module: wine
Branch: master
Commit: 8915500868a4be4838af5a2c84bdf2fc67406b1e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=8915500868a4be4838af5a2c84bdf2fc67406b1e
Author: Zhiyi Zhang <zzhang at codeweavers.com>
Date: Tue Oct 20 15:42:24 2020 +0800
ddraw/tests: Fix possible memory leaks.
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ddraw/tests/d3d.c | 21 ++++++++++++++++++++-
dlls/ddraw/tests/dsurface.c | 9 +++++++++
dlls/ddraw/tests/refcount.c | 3 +++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/dlls/ddraw/tests/d3d.c b/dlls/ddraw/tests/d3d.c
index 93ff6e296cc..d8f3618200b 100644
--- a/dlls/ddraw/tests/d3d.c
+++ b/dlls/ddraw/tests/d3d.c
@@ -109,7 +109,11 @@ static BOOL CreateDirect3D(void)
ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
- if (rc == E_NOINTERFACE) return FALSE;
+ if (rc == E_NOINTERFACE)
+ {
+ IDirectDraw7_Release(lpDD);
+ return FALSE;
+ }
ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
memset(&ddsd, 0, sizeof(ddsd));
@@ -120,7 +124,11 @@ static BOOL CreateDirect3D(void)
ddsd.dwHeight = 256;
rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
if (FAILED(rc))
+ {
+ IDirect3D7_Release(lpD3D);
+ IDirectDraw7_Release(lpDD);
return FALSE;
+ }
num = 0;
IDirectDraw7_EnumSurfaces(lpDD, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST, NULL, &num, SurfaceCounter);
@@ -144,7 +152,13 @@ static BOOL CreateDirect3D(void)
rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
if (FAILED(rc))
+ {
+ IDirectDrawSurface7_Release(lpDDSdepth);
+ IDirectDrawSurface7_Release(lpDDS);
+ IDirect3D7_Release(lpD3D);
+ IDirectDraw7_Release(lpDD);
return FALSE;
+ }
}
rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
@@ -160,6 +174,11 @@ static BOOL CreateDirect3D(void)
&lpD3DDevice);
if (!lpD3DDevice) {
trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
+ if (lpDDSdepth)
+ IDirectDrawSurface7_Release(lpDDSdepth);
+ IDirectDrawSurface7_Release(lpDDS);
+ IDirect3D7_Release(lpD3D);
+ IDirectDraw7_Release(lpDD);
return FALSE;
}
}
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index af18fc217b1..478fb5d4a27 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -165,6 +165,9 @@ static void GetDDInterface_2(void)
if(ret != DD_OK)
{
ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
+ IDirectDraw2_Release(dd2);
+ IDirectDraw4_Release(dd4);
+ IDirectDraw7_Release(dd7);
return;
}
ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
@@ -226,6 +229,9 @@ static void GetDDInterface_4(void)
if(ret != DD_OK)
{
ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
+ IDirectDraw2_Release(dd2);
+ IDirectDraw4_Release(dd4);
+ IDirectDraw7_Release(dd7);
return;
}
ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
@@ -297,6 +303,9 @@ static void GetDDInterface_7(void)
if(ret != DD_OK)
{
ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
+ IDirectDraw2_Release(dd2);
+ IDirectDraw4_Release(dd4);
+ IDirectDraw7_Release(dd7);
return;
}
ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
diff --git a/dlls/ddraw/tests/refcount.c b/dlls/ddraw/tests/refcount.c
index 447e6a99c67..07673ab66e9 100644
--- a/dlls/ddraw/tests/refcount.c
+++ b/dlls/ddraw/tests/refcount.c
@@ -97,6 +97,9 @@ static void test_ddraw_objects(void)
if (!surface)
{
win_skip("Could not create surface : %08x\n", hr);
+ IDirectDraw_Release(DDraw1);
+ IDirectDraw2_Release(DDraw2);
+ IDirectDraw4_Release(DDraw4);
IDirectDraw7_Release(DDraw7);
return;
}
More information about the wine-cvs
mailing list