瀏覽代碼

Memory leaks

Source commit: 08d872ed02a1daced24a57bc96820ee959c0e109
Martin Prikryl 3 天之前
父節點
當前提交
8e5c0b74c0
共有 3 個文件被更改,包括 15 次插入8 次删除
  1. 3 1
      source/packages/filemng/BaseUtils.pas
  2. 10 6
      source/windows/GUITools.cpp
  3. 2 1
      source/windows/Tools.cpp

+ 3 - 1
source/packages/filemng/BaseUtils.pas

@@ -60,7 +60,7 @@ resourcestring
 implementation
 
 uses
-  Windows, SysUtils, DateUtils, SysConst, Math, PIDL, Forms;
+  Windows, SysUtils, DateUtils, SysConst, Math, PIDL, Forms, Winapi.Ole2;
 
 function StrContains(Str1, Str2: string): Boolean;
 var
@@ -260,6 +260,8 @@ var
   PIDL: PItemIDList;
 begin
   Result := SpecialFolderLocation(Folder, Path, PIDL);
+  if Result then
+    CoTaskMemFree(PIDL);
 end;
 
 function FormatLastOSError(Message: string): string;

+ 10 - 6
source/windows/GUITools.cpp

@@ -885,14 +885,18 @@ void __fastcall ExecuteShellCheckedAndWait(const UnicodeString Command,
 bool __fastcall SpecialFolderLocation(int PathID, UnicodeString & Path)
 {
   LPITEMIDLIST Pidl;
-  wchar_t Buf[256];
-  if (SHGetSpecialFolderLocation(NULL, PathID, &Pidl) == NO_ERROR &&
-      SHGetPathFromIDList(Pidl, Buf))
+  bool Result = SUCCEEDED(SHGetSpecialFolderLocation(NULL, PathID, &Pidl));
+  if (Result)
   {
-    Path = UnicodeString(Buf);
-    return true;
+    wchar_t Buf[MAX_PATH];
+    Result = SHGetPathFromIDList(Pidl, Buf);
+    CoTaskMemFree(Pidl);
+    if (Result)
+    {
+      Path = UnicodeString(Buf);
+    }
   }
-  return false;
+  return Result;
 }
 //---------------------------------------------------------------------------
 UnicodeString __fastcall UniqTempDir(const UnicodeString BaseDir, const UnicodeString Identity,

+ 2 - 1
source/windows/Tools.cpp

@@ -801,8 +801,9 @@ void __fastcall OpenFolderInExplorer(const UnicodeString & Path)
 //---------------------------------------------------------------------------
 void __fastcall OpenFileInExplorer(const UnicodeString & Path)
 {
-  PCIDLIST_ABSOLUTE Folder = ILCreateFromPathW(ApiPath(Path).c_str());
+  PIDLIST_ABSOLUTE Folder = ILCreateFromPathW(ApiPath(Path).c_str());
   SHOpenFolderAndSelectItems(Folder, 0, NULL, 0);
+  ILFree(Folder);
 }
 //---------------------------------------------------------------------------
 void __fastcall ShowHelp(const UnicodeString & AHelpKeyword)