=?UTF-8?Q?Stefan=20D=C3=B6singer=20?=: ddrawex: Don't leak surfaces.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Sep 4 14:48:39 CDT 2014


Module: wine
Branch: master
Commit: 28850ae5f84b2d1746de52dc1c915e0a6bb5f824
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=28850ae5f84b2d1746de52dc1c915e0a6bb5f824

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Thu Sep  4 13:18:16 2014 +0200

ddrawex: Don't leak surfaces.

dds_get_outer AddRefs the inner surface when it creates the wrapper
surface. The wrapper releases only one reference when it is destroyed,
leaking one of the two. AddRefing in dds_get_outer makes sense because
this is also used by e.g. GetAttachedSurface, where it creates a new
wrapper for surfaces ddrawex didn't know about yet.

---

 dlls/ddrawex/ddraw.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/dlls/ddrawex/ddraw.c b/dlls/ddrawex/ddraw.c
index af23c89..b32f726 100644
--- a/dlls/ddrawex/ddraw.c
+++ b/dlls/ddrawex/ddraw.c
@@ -338,6 +338,7 @@ static HRESULT WINAPI ddrawex4_CreateSurface(IDirectDraw4 *iface, DDSURFACEDESC2
     HRESULT hr;
     const DWORD perm_dc_flags = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
     BOOL permanent_dc;
+    IDirectDrawSurface4 *inner_surface;
 
     TRACE("iface %p, desc %p, surface %p, outer_unknown %p.\n",
             iface, desc, surface, outer_unknown);
@@ -362,8 +363,17 @@ static HRESULT WINAPI ddrawex4_CreateSurface(IDirectDraw4 *iface, DDSURFACEDESC2
         permanent_dc = FALSE;
     }
 
-    hr = IDirectDraw4_CreateSurface(ddrawex->parent, desc, surface, outer_unknown);
-    *surface = dds_get_outer(*surface);
+    hr = IDirectDraw4_CreateSurface(ddrawex->parent, desc, &inner_surface, outer_unknown);
+    if (FAILED(hr))
+    {
+        *surface = NULL;
+        return hr;
+    }
+
+    *surface = dds_get_outer(inner_surface);
+    /* The wrapper created by dds_get_outer holds a reference to its inner surface. */
+    IDirectDrawSurface4_Release(inner_surface);
+
     if (permanent_dc)
         prepare_permanent_dc(*surface);
 




More information about the wine-cvs mailing list