[PATCH] gdi32/enhmfdrv: Do not leak a HDC

Detlef Riekenberg wine.dev at web.de
Fri Aug 20 07:45:00 CDT 2010


---
 dlls/gdi32/enhmfdrv/init.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/dlls/gdi32/enhmfdrv/init.c b/dlls/gdi32/enhmfdrv/init.c
index 279300d..4f3536b 100644
--- a/dlls/gdi32/enhmfdrv/init.c
+++ b/dlls/gdi32/enhmfdrv/init.c
@@ -302,7 +302,7 @@ HDC WINAPI CreateEnhMetaFileW(
     )
 {
     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
-    HDC ret;
+    HDC ret = NULL;
     DC *dc;
     HDC hRefDC = hdc ? hdc : CreateDCW(displayW,NULL,NULL,NULL); 
         /* If no ref, use current display */
@@ -312,12 +312,13 @@ HDC WINAPI CreateEnhMetaFileW(
 
     TRACE("%s\n", debugstr_w(filename) );
 
-    if (!(dc = alloc_dc_ptr( &EMFDRV_Funcs, OBJ_ENHMETADC ))) return 0;
+    if (!(dc = alloc_dc_ptr( &EMFDRV_Funcs, OBJ_ENHMETADC )))
+        goto cleanup;
 
     physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
     if (!physDev) {
         free_dc_ptr( dc );
-        return 0;
+        goto cleanup;
     }
     dc->physDev = (PHYSDEV)physDev;
     physDev->hdc = dc->hSelf;
@@ -333,7 +334,7 @@ HDC WINAPI CreateEnhMetaFileW(
     if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
         HeapFree( GetProcessHeap(), 0, physDev );
         free_dc_ptr( dc );
-        return 0;
+        goto cleanup;
     }
 
     physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
@@ -405,11 +406,11 @@ HDC WINAPI CreateEnhMetaFileW(
         if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0,
 				 NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
             EMFDRV_DeleteDC( dc );
-            return 0;
+            goto cleanup;
         }
         if (!WriteFile( hFile, physDev->emh, size, NULL, NULL )) {
             EMFDRV_DeleteDC( dc );
-            return 0;
+            goto cleanup;
 	}
 	physDev->hFile = hFile;
     }
@@ -418,6 +419,7 @@ HDC WINAPI CreateEnhMetaFileW(
     ret = dc->hSelf;
     release_dc_ptr( dc );
 
+cleanup:
     if( !hdc )
       DeleteDC( hRefDC );
 
-- 
1.7.0.4




More information about the wine-patches mailing list