Santiago Amposta wrote 32 lines
Hello:
I use fpc 2.6.4 and I have a problem of memory leaks, strange errors,
etc. Finally I have tracked it to this:
TSimpleArrayString=object
List:array of String;
end;
TDerivedArrayString=object(TSimpleArrayString)
other_field:integer;
end;
procedure TestSimple;
var
A:TSimpleArrayString;
begin
setLength(A.List,0);
end;
procedure TestDerived;
var
A:TDerivedArrayString;
begin
setLength(A.List,0);
end;
TestSimple; // Works Fine,
TestDerived; // rises an exception SIGSEGV on setLength
What am I doing wrong?
I might be wrong... but I just tried:
stepping into TestSimple in the order OP specified, hovering over A.List (actually over .List only, see below*) gives
A.List = (0x0)
before setLength
and
A.List = ()
after the setLength;
then stepped through to TestDerived, in which the hover over .List gives
A.List = ()
before setLength,
and an External: SIGSEGV At Address 403CDC when trying to step over setLength
Then if I change the order
TestDerived; // first
TestSimple; // second
and step through, the A.List in Test Derived is A.List = () from the start, it is as-if it was preinitialized?
But then. If I comment out the other_field, both routines pass through with A.List = (0x0) in TestSimple before SetLength, it also seems to pass without a problem and without the * problem below, even with A.List = () before and after SetLength.
* problem : with the other_field still IN TDerivedArrayString, if I step through the (passing with no error) TestSimple, and hover mouse over A, I get a GDB crash. Regardless which A I hover over (the one in Test Derived does that too, even if out of scope [execution point currently in the other Test procedure] Again this does NOT happen with the other_field commented out.
If I run either one Test* procedures at a time between rebuilds, with other_field defined, TestSimple passes with no error,
TestDerived shows .List hovering A.List = (0x10000 '=') ; hovering over A crashes GDB too;
Say if I only leave TestDerived call, and if I pause execution before SetLength, hovering over .List in EITHER procedure shows A.List = () (yes even in TestSimple which is commented out in main begin..end;) (and I get GDB crash when hovering over A of either procedure)
BUT.
If I truly comment out the unused procedure, only leaving the one currently being tested, like TestDerived, hovering over .List before SetLength call gives A.List = (0x10000 '=') hovering over A crashes GDB
after rebuild, program completes with NO SIGSEGV.
?
FPC 2.6.4 under Lazarus 1.4.4 from tarball release [ 2015-10-03, svn 49931 i386-win32-win32/win64 ] under WinXP SP3.