[lazarus] StrPCopy bug

michael at tfdec1.fys.kuleuven.ac.be michael at tfdec1.fys.kuleuven.ac.be
Thu Jul 8 14:47:32 EDT 1999




On Thu, 8 Jul 1999, Michael A. Hess wrote:

> Shane Miller wrote:
> > 
> > Could someone else try and get some example to Peter please.  If
> > needed, send him the Lazarus code and pinpoint the location.  I think
> > I may have found the other problem with the gtk_widget_show error and
> > I am stalking that.
> 
> I won't be back in my office for another 2 1/2 hours at the least so I
> can't do it until then. However, given what you have found so far with
> the DispatchStr('resize') crash I tend to think that we might be do some
> bad pointer passing or something and stomping on memory that is just
> plain messing everything up. StrPCopy was first and we by passed that
> only to find something else that got messed up. Since a smaller program
> StrPCopy does work I am leaning towards it being our problem. We are
> going to have to isolate parts of the code little by little until we
> find it.  :-\

Here is a test program I made:
-------------------------------------------------------
Program Example46;

{ This program demonstrates the StrBufSize function }
{$H+}

Uses heaptrc,sysutils;

Procedure DoTest;

Const S  = 'Some nice ansi string';

Var P : Pchar;
    SS : AnsiString;
Begin
   SS:=S+'!!!';
   P:=StrAlloc(Length(SS)+1);
   StrPCopy(P,SS);
   Write (P, ' has length ',length(SS));
   Writeln (' and  buffer size ',StrBufSize(P));
   StrDispose(P);
End;

Var L : longint;

begin
  L:=Memavail;
  Writeln('Mem :',L);
  DoTest;
  Writeln ('Mem : ',Memavail,' or lost ',L-Memavail,'bytes');
end.
------------------------------------------------------------

here is the output:

------------------------------------------------------------
home: >ex46
Mem :262016
Some nice ansi string!!! has length 24 and  buffer size 25
Mem : 262016 or lost 0bytes
Heap dump by heaptrc unit
7 memory blocks allocated : 125/144
5 memory blocks freed     : 101/112
2 unfreed memory blocks : 24
True heap size : 262144
True free heap : 262016
Should be : 262016
Call trace for block 0x08062600 size 12
  0x080592E2
  0x080551A0
  0x08053B09
  0x08053C04
  0x08058D65
  0x0805D49F
  0x080480A4
Call trace for block 0x080625C0 size 12
  0x080592E2
  0x080551A0
  0x08053AF1
  0x08053C04
  0x08058D65
  0x0805D49F
------------------------------------------------------------

Remark the '0 bytes lost.'

The 2 allocated blocks that heaptrc cmplains about are because 
2 exception objects that are allocated in iitialization code of
the sysutils unit are never freed (no finalization code yet), 
they have nothing to do with the StrPCopy.

Michael.






More information about the Lazarus mailing list