1
0
mirror of synced 2024-09-19 01:36:08 +00:00

Memory issue when using SHGetSpecialFolderLocation (deprecated)

This commit is contained in:
Jan Middelburg 2021-12-03 13:23:05 +01:00 committed by GitHub
parent b779a0e6af
commit c0ca278638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -418,33 +418,43 @@ procedure TX2App.GetPath();
(APath);
end;
var
ifMalloc: IMalloc;
pIDL: PItemIDList;
cPath: array[0..MAX_PATH] of Char;
{$IFNDEF DXE2PLUS}
procedure GetPaths;
var
ifMalloc: IMalloc;
pIDL: PItemIDList;
cPath: array[0..MAX_PATH] of Char;
begin
SHGetMalloc(ifMalloc);
try
FillChar(cPath, SizeOf(cPath), #0);
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, pIDL);
SHGetPathFromIDList(pIDL, @cPath);
FUserPath := FixPath(cPath);
cPath := '';
FillChar(cPath, SizeOf(cPath), #0);
SHGetSpecialFolderLocation(0, CSIDL_COMMON_APPDATA, pIDL);
SHGetPathFromIDList(pIDL, @cPath);
FProgramDataPath := FixPath(cPath);
finally
ifMalloc := nil;
end;
end;
{$ENDIF}
begin
FFileName := GetModule(SysInit.HInstance);
FPath := FixPath(ExtractFilePath(FFileName));
FMainPath := FixPath(ExtractFilePath(GetModule(0)));
SHGetMalloc(ifMalloc);
try
FillChar(cPath, SizeOf(cPath), #0);
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, pIDL);
SHGetPathFromIDList(pIDL, @cPath);
FUserPath := FixPath(cPath);
FillChar(cPath, SizeOf(cPath), #0);
SHGetSpecialFolderLocation(0, CSIDL_COMMON_APPDATA, pIDL);
SHGetPathFromIDList(pIDL, @cPath);
FProgramDataPath := FixPath(cPath);
finally
ifMalloc := nil;
end;
{$IFDEF DXE2PLUS}
FUserPath := FixPath(System.IOUtils.TPath.GetHomePath);
FProgramDataPath := FixPath(System.IOUtils.TPath.GetPublicPath);
{$ELSE}
GetPaths;
{$ENDIF}
end;