[CMD]
authorKamil Hornicek <kamil.hornicek@reactos.org>
Tue, 21 Oct 2014 16:05:54 +0000 (16:05 +0000)
committerKamil Hornicek <kamil.hornicek@reactos.org>
Tue, 21 Oct 2014 16:05:54 +0000 (16:05 +0000)
- fix resource leaks CID 716324, 716323, 716322, 716321, 716320, 716319, 716318

svn path=/trunk/; revision=64871

reactos/base/shell/cmd/copy.c
reactos/base/shell/cmd/internal.c
reactos/base/shell/cmd/move.c
reactos/base/shell/cmd/replace.c

index c5c127f..cc72cd8 100644 (file)
@@ -136,6 +136,7 @@ copy(TCHAR source[MAX_PATH],
         _tcscat(TempSrc,_T(".decrypt"));
         if (!CopyFileEx(source, TempSrc, NULL, NULL, FALSE, COPY_FILE_ALLOW_DECRYPTED_DESTINATION))
         {
+            CloseHandle (hFileSrc);
             nErrorLevel = 1;
             return 0;
         }
@@ -766,6 +767,7 @@ INT cmd_copy(LPTSTR param)
             /* Check Breaker */
             if (CheckCtrlBreak(BREAK_INPUT))
             {
+                FindClose(hFile);
                 freep(arg);
                 return 1;
             }
@@ -789,6 +791,7 @@ INT cmd_copy(LPTSTR param)
             if (_tcscmp(tmpDestPath, _T("\\\\.\\")) &&
                 !IsExistingDirectory(tmpDestPath))
             {
+                FindClose(hFile);
                 ConOutFormatMessage(GetLastError(), szSrcPath);
                 freep(arg);
                 nErrorLevel = 1;
index 925f2c3..14245d6 100644 (file)
@@ -382,7 +382,10 @@ BOOL DeleteFolder(LPTSTR FileName)
             {
                 SetFileAttributes(TempFileName,FILE_ATTRIBUTE_NORMAL);
                 if (!DeleteFile(TempFileName))
+                {
+                    FindClose (hFile);
                     return 0;
+                }
             }
 
         }while (FindNextFile (hFile, &f));
index f557f31..dd7dca9 100644 (file)
@@ -100,7 +100,7 @@ INT cmd_move (LPTSTR param)
     HANDLE hFile;
 
     /* used only when source and destination  directories are on different volume */
-    HANDLE hDestFile;
+    HANDLE hDestFile = NULL;
     WIN32_FIND_DATA findDestBuffer;
     TCHAR szMoveDest[MAX_PATH];
     TCHAR szMoveSrc[MAX_PATH];
@@ -505,6 +505,9 @@ INT cmd_move (LPTSTR param)
             FindNextFile (hFile, &findBuffer));
     FindClose (hFile);
 
+    if(hDestFile && hDestFile != INVALID_HANDLE_VALUE)
+        FindClose(hDestFile);
+
     freep (arg);
     return 0;
 }
index 864e3fb..9f19d74 100644 (file)
@@ -131,7 +131,10 @@ INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *d
         else
             ConOutResPrintf(STRING_REPLACE_HELP10, dest);
         if ( !FilePromptYNA (0))
+        {
+            CloseHandle (hFileSrc);
             return 0;
+        }
     }
 
     /* Output depending on add flag */
@@ -220,7 +223,7 @@ INT recReplace(DWORD dwFlags,
     HANDLE hFile;
     WIN32_FIND_DATA findBuffer;
 
-    /* Get file handel to the sourcefile(s) */
+    /* Get file handle to the sourcefile(s) */
     hFile = FindFirstFile (szSrcPath, &findBuffer);
 
     /*
@@ -302,6 +305,8 @@ INT recReplace(DWORD dwFlags,
     /* Take next sourcefile if any */
     } while(FindNextFile (hFile, &findBuffer));
 
+    FindClose(hFile);
+
     return filesReplaced;
 }
 
@@ -378,6 +383,8 @@ INT recFindSubDirs(DWORD dwFlags,
         /* Get the next handle */
     } while(FindNextFile (hFile, &findBuffer));
 
+    FindClose(hFile);
+
     return filesReplaced;
 }