Don't use explicit memory management

And avoid dangling pointers.
Original PR #16705.
This commit is contained in:
Chocobo1
2022-03-27 14:17:42 +08:00
committed by GitHub
parent ede7c8acbb
commit c621cae43b
9 changed files with 28 additions and 38 deletions

View File

@@ -113,9 +113,9 @@ namespace
{
QPixmap pixmapForExtension(const QString &ext) const override
{
const QString extWithDot = QLatin1Char('.') + ext;
const std::wstring extWStr = QString(QLatin1Char('.') + ext).toStdWString();
SHFILEINFO sfi {};
HRESULT hr = ::SHGetFileInfoW(extWithDot.toStdWString().c_str(),
HRESULT hr = ::SHGetFileInfoW(extWStr.c_str(),
FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
if (FAILED(hr))
return {};

View File

@@ -172,7 +172,8 @@ void Utils::Gui::openFolderSelect(const QString &absolutePath)
{
if (SUCCEEDED(::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
{
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<const wchar_t *>(Utils::Fs::toNativePath(path).utf16()));
const std::wstring pathWStr = Utils::Fs::toNativePath(path).toStdWString();
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(pathWStr.c_str());
if (pidl)
{
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);