From cd1f57b5d4a23196706cf9e3eacff31a5f9af409 Mon Sep 17 00:00:00 2001 From: Kamil Hornicek Date: Tue, 21 Oct 2014 16:05:54 +0000 Subject: [PATCH] [CMD] - fix resource leaks CID 716324, 716323, 716322, 716321, 716320, 716319, 716318 svn path=/trunk/; revision=64871 --- reactos/base/shell/cmd/copy.c | 3 +++ reactos/base/shell/cmd/internal.c | 3 +++ reactos/base/shell/cmd/move.c | 5 ++++- reactos/base/shell/cmd/replace.c | 9 ++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/reactos/base/shell/cmd/copy.c b/reactos/base/shell/cmd/copy.c index c5c127f573b..cc72cd8c2d8 100644 --- a/reactos/base/shell/cmd/copy.c +++ b/reactos/base/shell/cmd/copy.c @@ -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; diff --git a/reactos/base/shell/cmd/internal.c b/reactos/base/shell/cmd/internal.c index 925f2c3b46d..14245d6572b 100644 --- a/reactos/base/shell/cmd/internal.c +++ b/reactos/base/shell/cmd/internal.c @@ -382,7 +382,10 @@ BOOL DeleteFolder(LPTSTR FileName) { SetFileAttributes(TempFileName,FILE_ATTRIBUTE_NORMAL); if (!DeleteFile(TempFileName)) + { + FindClose (hFile); return 0; + } } }while (FindNextFile (hFile, &f)); diff --git a/reactos/base/shell/cmd/move.c b/reactos/base/shell/cmd/move.c index f557f31496c..dd7dca968af 100644 --- a/reactos/base/shell/cmd/move.c +++ b/reactos/base/shell/cmd/move.c @@ -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; } diff --git a/reactos/base/shell/cmd/replace.c b/reactos/base/shell/cmd/replace.c index 864e3fb6e24..9f19d746dc4 100644 --- a/reactos/base/shell/cmd/replace.c +++ b/reactos/base/shell/cmd/replace.c @@ -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; } -- 2.17.1