[fpc-devel] TVarRec.VAnsiString memory leak?

petr.kristan at epos.cz petr.kristan at epos.cz
Fri Mar 28 09:16:18 CET 2008


Hi.

This construction of setup vr.VAnsiString cause memoryleak:

program str;
uses
  heaptrc;
var
  s: ansistring;
  vr: TVarRec;
begin
  SetString(s, 'xxx', 3); //ok
  vr.VType := vtAnsiString;
  SetString(AnsiString(vr.VAnsiString), 'yyy', 3); //Memory leak.
end.

Heap dump by heaptrc unit
2 memory blocks allocated : 24/32
1 memory blocks freed     : 12/16
1 unfreed memory blocks : 12
True heap size : 32768
True free heap : 32672
Should be : 32688
Call trace for block $B7FEE0C0 size 12
  $08050E82  $fpc_ansistr_setlength,  line 569 of /home/common/fpc/rtl/inc/astrings.inc
  $080480DF  main,  line 10 of str.pas
  $080678B1  _FPC_proc_start,  line 67 of ./i386/si_prc.inc


Is right that in destroying TVarRec is not decremented ansistring reference?
If so, how to correctly set TVarRec.VAnsiString without memoryleak? 
I need to fill "a: array of TVarRec" with ansistrings.

Thanks.

Petr

-- 
Ing. Petr Kristan
.
EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice
tel: +420 466335223    Czech Republic (Eastern Europe) 
fax: +420 466510709



More information about the fpc-devel mailing list