From 1036ca0df66d4b286448ff474601b7896debce44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Fri, 16 Feb 2007 19:08:09 +0100 Subject: [PATCH] ddraw: Creating surfaces with old interfaces doesn't addref. --- dlls/ddraw/ddraw_thunks.c | 6 ++---- dlls/ddraw/surface.c | 2 +- dlls/ddraw/tests/refcount.c | 26 ++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/dlls/ddraw/ddraw_thunks.c b/dlls/ddraw/ddraw_thunks.c index ce61f18528d..964466d0283 100644 --- a/dlls/ddraw/ddraw_thunks.c +++ b/dlls/ddraw/ddraw_thunks.c @@ -410,8 +410,7 @@ IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc, IDirectDraw, IDirectDraw7, This)); - IDirectDraw_AddRef(This); - impl->ifaceToRelease = (IUnknown *) This; + impl->ifaceToRelease = NULL; } return hr; @@ -446,8 +445,7 @@ IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc, IDirectDraw2, IDirectDraw7, This)); - IDirectDraw2_AddRef(This); - impl->ifaceToRelease = (IUnknown *) This; + impl->ifaceToRelease = NULL; } return hr; diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index cd358320c31..c41d08f99a9 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -376,7 +376,7 @@ IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface) IDirectDrawSurfaceImpl_Destroy(This); /* Reduce the ddraw refcount */ - IUnknown_Release(ifaceToRelease); + if(ifaceToRelease) IUnknown_Release(ifaceToRelease); } return ref; diff --git a/dlls/ddraw/tests/refcount.c b/dlls/ddraw/tests/refcount.c index b79612f9558..11301d3d8d6 100644 --- a/dlls/ddraw/tests/refcount.c +++ b/dlls/ddraw/tests/refcount.c @@ -49,10 +49,12 @@ static void test_ddraw_objects(void) unsigned long ref; IDirectDraw7 *DDraw7; IDirectDraw4 *DDraw4; - IDirectDraw4 *DDraw2; - IDirectDraw4 *DDraw1; + IDirectDraw2 *DDraw2; + IDirectDraw *DDraw1; IDirectDrawPalette *palette; IDirectDrawSurface7 *surface; + IDirectDrawSurface *surface1; + IDirectDrawSurface4 *surface4; PALETTEENTRY Table[256]; DDSURFACEDESC2 ddsd; @@ -163,6 +165,26 @@ static void test_ddraw_objects(void) ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawPalette_Release(palette); + /* Simmilar for surfaces */ + hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL); + ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); + ref = getRefcount( (IUnknown *) DDraw4); + ok(ref == 2, "Got refcount %ld, expected 2\n", ref); + IDirectDrawSurface4_Release(surface4); + + ddsd.dwSize = sizeof(DDSURFACEDESC); + hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL); + ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); + ref = getRefcount( (IUnknown *) DDraw2); + ok(ref == 1, "Got refcount %ld, expected 1\n", ref); + IDirectDrawSurface_Release(surface1); + + hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL); + ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); + ref = getRefcount( (IUnknown *) DDraw1); + ok(ref == 1, "Got refcount %ld, expected 1\n", ref); + IDirectDrawSurface_Release(surface1); + IDirectDraw7_Release(DDraw7); IDirectDraw4_Release(DDraw4); IDirectDraw2_Release(DDraw2);