[PATCH 5/5] wined3d: Don't depend on uninitialized data in the CreateSurface() thunks (Valgrind).

Henri Verbeet hverbeet at codeweavers.com
Thu Oct 29 04:37:13 CDT 2009


Perhaps IDirectDraw7_CreateSurface() should also always set "pSurface7" to
NULL on failure, but at least for our internal functions that's a silly thing
to rely on.
---
 dlls/ddraw/ddraw_thunks.c |   62 ++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/dlls/ddraw/ddraw_thunks.c b/dlls/ddraw/ddraw_thunks.c
index 8c79cbf..278d720 100644
--- a/dlls/ddraw/ddraw_thunks.c
+++ b/dlls/ddraw/ddraw_thunks.c
@@ -347,20 +347,18 @@ IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
      * since the data layout is the same */
     hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw1(This),
             (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
-
-    /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
-     * IDirectDrawSurface vtable layout at the beginning  */
-    *ppSurface = pSurface7 ?
-            (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurface7)->IDirectDrawSurface3_vtbl : NULL;
-
-    impl = (IDirectDrawSurfaceImpl *)pSurface7;
-    if(SUCCEEDED(hr) && impl)
+    if (FAILED(hr))
     {
-        set_surf_version(impl, 1);
-        IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This));
-        impl->ifaceToRelease = NULL;
+        *ppSurface = NULL;
+        return hr;
     }
 
+    impl = (IDirectDrawSurfaceImpl *)pSurface7;
+    *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
+    set_surf_version(impl, 1);
+    IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This));
+    impl->ifaceToRelease = NULL;
+
     return hr;
 }
 
@@ -375,20 +373,18 @@ IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
 
     hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw2(This),
             (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
-
-    /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
-     * IDirectDrawSurface vtable layout at the beginning  */
-    *ppSurface = pSurface7 ?
-            (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurface7)->IDirectDrawSurface3_vtbl : NULL;
-
-    impl = (IDirectDrawSurfaceImpl *)pSurface7;
-    if(SUCCEEDED(hr) && impl)
+    if (FAILED(hr))
     {
-        set_surf_version(impl, 2);
-        IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw2(This));
-        impl->ifaceToRelease = NULL;
+        *ppSurface = NULL;
+        return hr;
     }
 
+    impl = (IDirectDrawSurfaceImpl *)pSurface7;
+    *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
+    set_surf_version(impl, 2);
+    IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw2(This));
+    impl->ifaceToRelease = NULL;
+
     return hr;
 }
 
@@ -403,21 +399,19 @@ IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc,
 
     hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw3(This),
             (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
-
-    /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
-     * IDirectDrawSurface vtable layout at the beginning  */
-    *ppSurface = pSurface7 ?
-            (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurface7)->IDirectDrawSurface3_vtbl : NULL;
-
-    impl = (IDirectDrawSurfaceImpl *)pSurface7;
-    if(SUCCEEDED(hr) && impl)
+    if (FAILED(hr))
     {
-        set_surf_version(impl, 3);
-        IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw3(This));
-        IDirectDraw3_AddRef(This);
-        impl->ifaceToRelease = (IUnknown *) This;
+        *ppSurface = NULL;
+        return hr;
     }
 
+    impl = (IDirectDrawSurfaceImpl *)pSurface7;
+    *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
+    set_surf_version(impl, 3);
+    IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw3(This));
+    IDirectDraw3_AddRef(This);
+    impl->ifaceToRelease = (IUnknown *) This;
+
     return hr;
 }
 
-- 
1.6.4.4




More information about the wine-patches mailing list