From 8e7d72058b8fad7fb0ccf94583ef48b049e3c3fb Mon Sep 17 00:00:00 2001 From: Kamil Hornicek Date: Thu, 11 Mar 2010 14:57:05 +0000 Subject: [PATCH] [SHELL32] - partial Wine sync, fixes crashing shlfileop winetest: Use the current directory when copying to an empty destination. Fix a memory leak in SHFileOperationW. Vincent Povirk svn path=/trunk/; revision=46098 --- reactos/dll/win32/shell32/shlfileop.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/reactos/dll/win32/shell32/shlfileop.c b/reactos/dll/win32/shell32/shlfileop.c index b8e0568a65b..e3bdf6eac31 100644 --- a/reactos/dll/win32/shell32/shlfileop.c +++ b/reactos/dll/win32/shell32/shlfileop.c @@ -1087,6 +1087,20 @@ static HRESULT copy_files(FILE_OPERATION *op, const FILE_LIST *flFrom, FILE_LIST if (flFrom->bAnyDontExist) return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND; + if (flTo->dwNumFiles == 0) + { + /* If the destination is empty, SHFileOperation should use the current directory */ + WCHAR curdir[MAX_PATH+1]; + + GetCurrentDirectoryW(MAX_PATH, curdir); + curdir[lstrlenW(curdir)+1] = 0; + + destroy_file_list(flTo); + ZeroMemory(flTo, sizeof(FILE_LIST)); + parse_file_list(flTo, curdir); + fileDest = &flTo->feFiles[0]; + } + if (op->req->fFlags & FOF_MULTIDESTFILES) { if (flFrom->bAnyFromWildcard) @@ -1097,6 +1111,14 @@ static HRESULT copy_files(FILE_OPERATION *op, const FILE_LIST *flFrom, FILE_LIST if (flFrom->dwNumFiles != 1 && !IsAttribDir(fileDest->attributes)) return ERROR_CANCELLED; + /* Free all but the first entry. */ + for (i = 1; i < flTo->dwNumFiles; i++) + { + HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szDirectory); + HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szFilename); + HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szFullPath); + } + flTo->dwNumFiles = 1; } else if (IsAttribDir(fileDest->attributes))