version: fix handle leaks

Pierre Schweitzer pierre at reactos.org
Thu Dec 8 16:05:48 CST 2011


-------------- next part --------------
>From de20355c9f54d9531454d9ca37a462604da0edcb Mon Sep 17 00:00:00 2001
From: Pierre Schweitzer <pierre at reactos.org>
Date: Thu, 8 Dec 2011 23:02:44 +0100
Subject: version: Fix handle leaks

---
 dlls/version/version.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/dlls/version/version.c b/dlls/version/version.c
index bc90dcc..ae581e6 100644
--- a/dlls/version/version.c
+++ b/dlls/version/version.c
@@ -1021,6 +1021,7 @@ static int testFileExistenceA( char const * path, char const * file, BOOL excl )
     char  filename[1024];
     int  filenamelen;
     OFSTRUCT  fileinfo;
+    HFILE filehandle;
 
     fileinfo.cBytes = sizeof(OFSTRUCT);
 
@@ -1038,8 +1039,13 @@ static int testFileExistenceA( char const * path, char const * file, BOOL excl )
     /* Create the full pathname */
     strcat(filename, file);
 
-    return (OpenFile(filename, &fileinfo,
-                     OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
+    filehandle = OpenFile(filename, &fileinfo,
+                          OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0));
+    if (filehandle == HFILE_ERROR)
+        return 0;
+
+    CloseHandle((HANDLE)filehandle);
+    return 1;
 }
 
 /******************************************************************************
@@ -1049,8 +1055,8 @@ static int testFileExistenceW( const WCHAR *path, const WCHAR *file, BOOL excl )
 {
     char *filename;
     DWORD pathlen, filelen;
-    int ret;
     OFSTRUCT fileinfo;
+    HFILE filehandle;
 
     fileinfo.cBytes = sizeof(OFSTRUCT);
 
@@ -1069,10 +1075,15 @@ static int testFileExistenceW( const WCHAR *path, const WCHAR *file, BOOL excl )
 
     WideCharToMultiByte( CP_ACP, 0, file, -1, filename+strlen(filename), filelen, NULL, NULL );
 
-    ret = (OpenFile(filename, &fileinfo,
-                    OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
+    filehandle = OpenFile(filename, &fileinfo,
+                          OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0));
     HeapFree( GetProcessHeap(), 0, filename );
-    return ret;
+
+    if (filehandle == HFILE_ERROR)
+        return 0;
+
+    CloseHandle((HANDLE)filehandle);
+    return 1;
 }
 
 /*****************************************************************************
-- 
1.7.4.1



More information about the wine-patches mailing list