Forum Discussion

jacob_hoover's avatar
jacob_hoover
New Contributor
14 years ago

0 byte memory leak a false positive?

Delphi 2010

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.

2 Replies

  • I neglected to state I was using the Allocation Profiler with all options checked.

  • Hello Jacob,





    As far as I know, you contacted us regarding the issue, and we have analyzed it deeply since then. 





    AQtime shows objects because it cannot detect that they are freed. This is a known problem, and we are working on it. Sorry for the inconvenience.





    As for the fact that the objects have zero sizes, it is expected behavior. The sizes are not specified explicitly in the SHGetSpecialFolderLocation function call, so AQtime cannot detect them.