简体   繁体   中英

Delphi - memory leak in TSevenZipVCL

testing for memory leaks with madhi's madExcept, and the component TSevenZipVCL ( http://www.rg-software.de ) it's reporting a leak here:

  POleStr = PWideChar;
  TBStr = POleStr;
    function TSevenZip.List: Integer;
    ...
      for i := 0 to w - 1 do
      begin
        name := new( TBSTR ); <-------
        ptype := 0;
        inA.GetPropertyInfo( i, name, prop, pType );

even if I add Dispose(name) the leak occurs, what could be wrong?

TSevenZip unit posted here: http://pastebin.com/bhvERDJv

inA.GetPropertyInfo( i, name, prop, pType );

This function appears to be passed an index in the first parameter, and the returns the information for the property with that index through the other parameters. The IInArchive interface has been very poorly translated by whoever wrote the code that you are calling. The function looks like this:

function GetPropertyInfo( index: DWORD; var name: TBSTR; var propID: PROPID; 
    var varType: {PVARTYPE}Integer ): Integer; stdcall;

The C++ declaration looks like this:

STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType);

The name parameter is a COM BSTR that is allocated in the function, and returned to the caller.

I would declare it like this:

function GetPropertyInfo( index: DWORD; out name: WideString; var propID: PROPID; 
    var varType: {PVARTYPE}Integer ): Integer; stdcall;

By doing this you will ensure that the compiler is able to deallocate the COM BSTR when you've done with it.

You should remove the call to New . It is completely spurious.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM