Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-06

SIGSEGV in fpc_check_object

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

In my Lazarus application I use a TPanel descendant component (TMyPanel) which have subpanels (TMySubPanel) which are TPanel descendants also. The subpanels accessed through a TList. If add a new subpanel into the main panel added to the list with TList.Add if remove a subpanel from it remove from the list with TList.Remove then call TMySubPanel.Free. My main development platform is x86_64-Linux and the application works like a charm. But with the Windows version of the app (cross compiled to i386-Win32) got an "Access violation." at TMySubPanel.Free. If start with gdb got "Program received signal SIGSEGV, Segmentation fault. 0x004041c4 in fpc_check_object ()" at TMySubPanel.Free.

I completely don't understand what is the source of the problem and why the two platforms behaves differently.

Cannot have a simple test case just a dumb example.

procedure TForm1.FormCreate(Sender: TObject);
var
   x:TPanel;
begin
   x.Free;
end;

With Linux no error (x is Nil before the Free call), with Windows got SIGSEGV (x is not Nil before the Free call). Is it a Lazarus thing or come from FPC?

Gabor

José Mejuto
to Gabor Boros
Gabor Boros wrote 13 lines
Cannot have a simple test case just a dumb example. procedure TForm1.FormCreate(Sender: TObject); var x:TPanel; begin x.Free; end; With Linux no error (x is Nil before the Free call), with Windows got SIGSEGV (x is not Nil before the Free call). Is it a Lazarus thing or come from FPC?

Hello,

That's wrong for sure, x is not initialized to nil, not in Linux nor in Windows. Procedure variables must be always initialized by hand. With that code you will get a warning from the compiler about uninitialized variable use.

Gabor Boros
to José Mejuto

2017. 06. 14. 10:28 keltezéssel, José Mejuto írta:

That's wrong for sure, x is not initialized to nil, not in Linux nor in Windows.

With the below code caption of the form not changed on Linux for me.

procedure TForm1.FormCreate(Sender: TObject);
var
   x:TPanel;
begin
   if Assigned(x) then Caption:='Assigned';
end;

Gabor

Sven Barth
to Gabor Boros
"Gabor Boros" wrote
2017. 06. 14. 10:28 keltezéssel, José Mejuto írta: > > That's wrong for sure, x is not initialized to nil, not in Linux nor in

Windows.

Show quoted text 12 lines
With the below code caption of the form not changed on Linux for me. procedure TForm1.FormCreate(Sender: TObject); var x:TPanel; begin if Assigned(x) then Caption:='Assigned'; end;

In this example the content of "x" is undefined as it's a local variable. The value of it is simply what is currently on the stack which *can* be Nil.

Regards,
Sven