cmd: Fix some unclosed file and registry handles

Lance Jackson lancej at lancej.net
Sat Dec 29 19:31:14 CST 2007


This is my first time submitting a patch, please let me know if
anything is wrong with it.

Changelog:
    cmd: Fix some unclosed file and registry handles

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

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 1d12706..4edaa46 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -73,6 +73,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
       h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ,
                       NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
       if (h != INVALID_HANDLE_VALUE) {
+        CloseHandle (h);
         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