cmd: Fix some unclosed file and registry handles (Resend)

Lance Jackson lancej at lancej.net
Thu Jan 3 18:03:44 CST 2008


The only thing I could think of that might have been a problem with my last
patch was that the unclosed handle from CreateFile in batch.c should be fixed
by removing it and checking if the file exists with GetFileAttributes since
the file handle isn't used at all.  I've changed the patch to do this instead.

If this wasn't the problem or there are other problems please let me know.

Changelog:
    cmd: Fix some unclosed file and registry handles

---
 programs/cmd/batch.c    |    4 +---
 programs/cmd/builtins.c |    2 +-
 programs/cmd/wcmdmain.c |    2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 1d12706..15057b3 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -70,9 +70,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
       strcpyW (string, file);
       CharLower (string);
       if (strstrW (string, extension_exe) == NULL) strcatW (string, extension_exe);
-      h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ,
-                      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-      if (h != INVALID_HANDLE_VALUE) {
+      if (GetFileAttributes (string) != INVALID_FILE_ATTRIBUTES) {
         WCMD_run_program (command, 0);
       } else {
         SetLastError (ERROR_FILE_NOT_FOUND);
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 43f63f6..549795c 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -2598,11 +2598,11 @@ void WCMD_assoc (WCHAR *command, BOOL assoc) {
                 WCMD_output_asis(keyValue);
               }
               WCMD_output_asis(newline);
+              RegCloseKey(readKey);
             }
           }
         }
       }
-      RegCloseKey(readKey);
 
     } else {
 
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 52a3108..16a0991 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -377,6 +377,7 @@ int wmain (int argc, WCHAR *argvW[])
                   value = strtoulW(strvalue, NULL, 10);
               }
           }
+          RegCloseKey(key);
       }
 
       if (value == 0 && RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKeyW,
@@ -397,6 +398,7 @@ int wmain (int argc, WCHAR *argvW[])
                   value = strtoulW(strvalue, NULL, 10);
               }
           }
+          RegCloseKey(key);
       }
 
       /* If one found, set the screen to that colour */
-- 
1.5.2.5




More information about the wine-patches mailing list