[fpc-devel] TVarRec.VAnsiString memory leak?

Michael Van Canneyt michael at freepascal.org
Fri Mar 28 10:17:01 CET 2008



On Fri, 28 Mar 2008, petr.kristan at epos.cz wrote:

> 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.

This is a correct way:

program str;

uses
  heaptrc;

var
  s,t: ansistring;
  vr: TVarRec;

begin
  SetString(s, 'xxx', 3); //ok
  vr.VType := vtAnsiString;
  t:='yyy';
  vr.VAnsiString:=Pointer(T); 
end.

Michael.



More information about the fpc-devel mailing list