0 byte memory leak a false positive?
AQTime 6.50.498.86
I am having an issue where AQTime is reporting a memory leak, where as far as I can tell there is none. I ahve searched the forums/news groups but haven't seen a reference to this. Test case follows and is also attached.
program FalsePositive;
{$APPTYPE CONSOLE}
uses
SysUtils,
ShlObj,
ActiveX,
Windows;
{-------------------------------------------------------------------------------
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10206340.html
http://msdn.microsoft.com/en-us/library/bb762203%28VS.85%29.aspx
The ppidl returned by SHGetSpecialFolderLocation must be freed by the caller
via CoTaskMemFree, per the MSDN specification. It is also possible to utilize
an IMalloc interface from SHGetMalloc called before hand, and then using it
to free it after using it.
-------------------------------------------------------------------------------}
function GetShellFolderIMalloc(const nFolder: Integer; const Name: String): Boolean;
var
Buffer: array[0..MAX_PATH] of Char;
ppidl: PItemIDList;
malloc: IMalloc;
begin
Result := False;
if (SHGetMalloc(malloc) = S_OK) and
(SHGetSpecialFolderLocation(0, nFolder, ppidl) = S_OK) then
try
SHGetPathFromIDList(ppidl, Buffer);
OutputDebugString(PChar(Format('%s -> %s', [Name, Buffer])));
Result := True;
finally
malloc.Free(ppidl);
end
else
OutputDebugString(PChar('Unable to locate "' + Name + '" folder in registry.'));
end;
function GetShellFolderCoTaskMemFree(const nFolder: Integer; const Name: String): Boolean;
var
Buffer: array[0..MAX_PATH] of Char;
ppidl: PItemIDList;
begin
Result := False;
if (SHGetSpecialFolderLocation(0, nFolder, ppidl) = S_OK) then
try
SHGetPathFromIDList(ppidl, Buffer);
OutputDebugString(PChar(Format('%s -> %s', [Name, Buffer])));
Result := True;
finally
CoTaskMemFree(ppidl);
end
else
OutputDebugString(PChar('Unable to locate "' + Name + '" folder in registry.'));
end;
begin
try
GetShellFolderIMalloc(CSIDL_COMMON_DESKTOPDIRECTORY, 'Common Desktop');
GetShellFolderCoTaskMemFree(CSIDL_COMMON_DESKTOPDIRECTORY, 'Common Desktop');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.