Alexandre Julliard : kernel32: Fix a couple of handle leaks.

Alexandre Julliard julliard at winehq.org
Thu May 26 10:56:25 CDT 2011


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu May 26 13:28:46 2011 +0200

kernel32: Fix a couple of handle leaks.

---

 dlls/kernel32/resource.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/dlls/kernel32/resource.c b/dlls/kernel32/resource.c
index 81f600e..b9a93c4 100644
--- a/dlls/kernel32/resource.c
+++ b/dlls/kernel32/resource.c
@@ -903,7 +903,6 @@ struct resource_size_info {
 
 struct mapping_info {
     HANDLE file;
-    HANDLE mapping;
     void *base;
     DWORD size;
     BOOL read_write;
@@ -1062,6 +1061,7 @@ static BOOL read_mapped_resources( QUEUEDUPDATES *updates, void *base, DWORD map
 static BOOL map_file_into_memory( struct mapping_info *mi )
 {
     DWORD page_attr, perm;
+    HANDLE mapping;
 
     if (mi->read_write)
     {
@@ -1074,15 +1074,13 @@ static BOOL map_file_into_memory( struct mapping_info *mi )
         perm = FILE_MAP_READ;
     }
 
-    mi->mapping = CreateFileMappingW( mi->file, NULL, page_attr, 0, 0, NULL );
-    if (!mi->mapping)
-        return FALSE;
+    mapping = CreateFileMappingW( mi->file, NULL, page_attr, 0, 0, NULL );
+    if (!mapping) return FALSE;
 
-    mi->base = MapViewOfFile( mi->mapping, perm, 0, 0, mi->size );
-    if (!mi->base)
-        return FALSE;
+    mi->base = MapViewOfFile( mapping, perm, 0, 0, mi->size );
+    CloseHandle( mapping );
 
-    return TRUE;
+    return mi->base != NULL;
 }
 
 static BOOL unmap_file_from_memory( struct mapping_info *mi )
@@ -1090,9 +1088,6 @@ static BOOL unmap_file_from_memory( struct mapping_info *mi )
     if (mi->base)
         UnmapViewOfFile( mi->base );
     mi->base = NULL;
-    if (mi->mapping)
-        CloseHandle( mi->mapping );
-    mi->mapping = NULL;
     return TRUE;
 }
 
@@ -1126,10 +1121,7 @@ static struct mapping_info *create_mapping( LPCWSTR name, BOOL rw )
         if (map_file_into_memory( mi ))
             return mi;
     }
-
-    unmap_file_from_memory( mi );
-    HeapFree( GetProcessHeap(), 0, mi );
-
+    destroy_mapping( mi );
     return NULL;
 }
 




More information about the wine-cvs mailing list