QuickLib
QuickLib copied to clipboard
Memory leak in Quick.Commons.GetSpecialFolderPath
Using Delphi 10.3 in Windows 10, setting ReportMemoryLeaksOnShutdown to True detects a memory leak in GetSpecialFolderPath function. As stated in https://www.experts-exchange.com/questions/10206340/Locating-special-folder.html, maybe you could consider a solution like:
implementation uses Winapi.ActiveX; ... function GetSpecialFolderPath(folderID : Integer) : string; var malloc : IMalloc; ppidl: PItemIdList; begin if (SHGetMalloc(malloc)=NOERROR) then begin SHGetSpecialFolderLocation(0, folderID, ppidl); SetLength(Result, MAX_PATH); if not SHGetPathFromIDList(ppidl,{$IFDEF FPC}PAnsiChar(Result){$ELSE}PChar(Result){$ENDIF}) then begin malloc.Free(ppidl); raise EShellError.create(Format('GetSpecialFolderPath: Invalid PIPL (%d)',[folderID])); end; SetLength(Result, lStrLen({$IFDEF FPC}PAnsiChar(Result){$ELSE}PChar(Result){$ENDIF})); malloc.Free(ppidl); end; end;
In my test, that solved the problem.
Regards,
Paolo
I tried with Windows 10 and Delphi 10.3:
ReportMemoryLeaksOnShutdown := True; for i := 0 to 100 do Writeln(path.USERPROFILE);
but no memory leaks was reported. Could you tell me how to reproduce it?
I'm sorry, I no longer have the code I used for testing that method. I remember we used it to read APPDATA in a VCL application.
I tested your code. With ReportMemoryLeaksOnShutdown you are right, no leak found.
But a memory leak is still found by madExcept: here is a screenshot.
Using path.APPDATA:

When I used the solution I proposed above, no leak was found.
Closing this issue as it has been inactive for an extended period of time and there has been no recent activity. If this issue is still relevant, please feel free to reopen it with updated information.