Zitat von Graeme Geldenhuys <graemeg.li...@gmail.com>:

[...]
* ntoc  = number of entries in the array. Each entry is a LongWord (or
Int32 in the code below)
* tocarray is my local array that gets populated with information from
the file, using the Move() procedure.
* tocoffsetsstart is the starting offset of the TOC array in the file.
* I then simply look through the number of entries in the array
  - position p to file offset as specified by each entry of the array
  - extract my data, and continue with the next item in the array

At the end I try to free / dispose of the memory used by my local
array: tocarray
...but whatever I try, heaptrc keeps telling me I have a memory leak
in this code.

--------------------------------------
procedure THelpFile.ReadContents;
var
  Topic: TTopic;
  EntryIndex: longint;
  pEntry: pTTOCEntryStart;
  tocarray: array of Int32;
  p: PByte;
begin
  _Topics.Capacity := _Header.ntoc;

  SetLength(tocarray, _Header.ntoc);
  p := _Data + _Header.tocoffsetsstart;
  Move(p, tocarray, SizeOf(tocarray));

if _Header.ntoc>0 then
  Move(p^,tocarray[0],SizeOf(Int32)*_Header.ntoc);

  for EntryIndex := 0 to _Header.ntoc-1 do
  begin
    pEntry := _Data + tocarray[EntryIndex];

Why not simply:
  pEntry := _Data + PInt32(p)[EntryIndex];

    Topic := TTopic.Create(_Data,
                           _Header,
                           _Dictionary,
                           pEntry );
    Topic.HelpFile := Self;
    Topic.Index := EntryIndex;
    _Topics.Add(Topic);
  end;
//  Finalize(tocarray);                        <--- doesn't work

not needed:

  Finalize(tocarray, _header.ntoc);       <--- doesn't work
  tocarray := nil;                                  <--- doesn't work
end;


Mattias


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to