From 0fbf4fb8fb8bbb3d37cf9e82d0e3b670838f4e04 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Thu, 11 Jul 2024 17:19:57 +0900 Subject: [PATCH] [BROWSEUI] Fix confusion of StrDupW and SHStrDupW (#7135) Fix memory leaks. SHStrDupW uses CoTaskMemAlloc. StrDupW uses LocalAlloc. They are different. JIRA issue: N/A Use SHStrDupW instead of StrDupW. --- dll/win32/browseui/parsecmdline.cpp | 3 ++- dll/win32/browseui/shellfind/CFindFolder.cpp | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dll/win32/browseui/parsecmdline.cpp b/dll/win32/browseui/parsecmdline.cpp index 83410f12602..07d7df7c4fa 100644 --- a/dll/win32/browseui/parsecmdline.cpp +++ b/dll/win32/browseui/parsecmdline.cpp @@ -402,7 +402,8 @@ SHExplorerParseCmdLine(_Out_ PEXPLORER_CMDLINE_PARSE_RESULTS pInfo) // The path could not be parsed into an ID List, // so pass it on as a plain string. - PWSTR field = StrDupW(strField); + PWSTR field; + SHStrDupW(strField, &field); pInfo->strPath = field; if (field) { diff --git a/dll/win32/browseui/shellfind/CFindFolder.cpp b/dll/win32/browseui/shellfind/CFindFolder.cpp index 999e57658eb..6e01db9c44a 100644 --- a/dll/win32/browseui/shellfind/CFindFolder.cpp +++ b/dll/win32/browseui/shellfind/CFindFolder.cpp @@ -428,11 +428,15 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData) FileNameMatch(FindData.cFileName, pSearchData) && AttribHiddenMatch(FindData.dwFileAttributes, pSearchData)) { - PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM) StrDupW(szPath)); + LPWSTR pszPathDup; + SHStrDupW(szPath, &pszPathDup); + PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM)pszPathDup); uTotalFound++; } status.Format(IDS_SEARCH_FOLDER, FindData.cFileName); - PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer())); + LPWSTR pszStatusDup; + SHStrDupW(status.GetBuffer(), &pszStatusDup); + PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM)pszStatusDup); uTotalFound += RecursiveFind(szPath, pSearchData); } @@ -441,7 +445,9 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData) && ContentsMatch(szPath, pSearchData)) { uTotalFound++; - PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM) StrDupW(szPath)); + LPWSTR pszPathDup; + SHStrDupW(szPath, &pszPathDup); + PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM)pszPathDup); } } @@ -465,7 +471,9 @@ DWORD WINAPI CFindFolder::SearchThreadProc(LPVOID lpParameter) CStringW status; status.Format(IDS_SEARCH_FILES_FOUND, uTotalFound); - ::PostMessageW(data->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer())); + LPWSTR pszStatusDup; + SHStrDupW(status.GetBuffer(), &pszStatusDup); + ::PostMessageW(data->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM)pszStatusDup); ::SendMessageW(data->hwnd, WM_SEARCH_STOP, 0, 0); CloseHandle(data->hStopEvent);