[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.
This commit is contained in:
Katayama Hirofumi MZ 2024-07-11 17:19:57 +09:00 committed by GitHub
parent 28e7af7531
commit 0fbf4fb8fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View file

@ -402,7 +402,8 @@ SHExplorerParseCmdLine(_Out_ PEXPLORER_CMDLINE_PARSE_RESULTS pInfo)
// The path could not be parsed into an ID List, // The path could not be parsed into an ID List,
// so pass it on as a plain string. // so pass it on as a plain string.
PWSTR field = StrDupW(strField); PWSTR field;
SHStrDupW(strField, &field);
pInfo->strPath = field; pInfo->strPath = field;
if (field) if (field)
{ {

View file

@ -428,11 +428,15 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
FileNameMatch(FindData.cFileName, pSearchData) && FileNameMatch(FindData.cFileName, pSearchData) &&
AttribHiddenMatch(FindData.dwFileAttributes, 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++; uTotalFound++;
} }
status.Format(IDS_SEARCH_FOLDER, FindData.cFileName); 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); uTotalFound += RecursiveFind(szPath, pSearchData);
} }
@ -441,7 +445,9 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
&& ContentsMatch(szPath, pSearchData)) && ContentsMatch(szPath, pSearchData))
{ {
uTotalFound++; 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; CStringW status;
status.Format(IDS_SEARCH_FILES_FOUND, uTotalFound); 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); ::SendMessageW(data->hwnd, WM_SEARCH_STOP, 0, 0);
CloseHandle(data->hStopEvent); CloseHandle(data->hStopEvent);