Sign in Join

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

Mailing lists / lazarus / 2014-06

App

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Petr Hlozek

Hi,

I have an Linux app, it has over 76k lines of code, 78 Forms and uses threads. After I close the app, it always crashes in

function TScreen.GetCustomFormsZOrdered(Index: Integer): TCustomForm;
begin
  Result := TCustomForm(FCustomFormsZOrdered[Index]);
end;

The index variable value is something like 42325 or so. I tried to debug and here is what I found out:

It goes through all FormCloseQuesry, FormDestroy and DatamoduleDestory, then it goes to
TApplication.DoBeforeFinalization and then into
TScreen..GetCustomFormsZOrdered where it fails.
I spent days trying to find out where could be the problem but didn't find anything. I'm lost. Do you have any idea where could be a problem, please? Thanks a lot!

Petr

Reply by email

Mattias Gaertner
to Petr Hlozek
Show quoted text 21 lines
Hi, I have an Linux app, it has over 76k lines of code, 78 Forms and uses threads. After I close the app, it always crashes in function TScreen.GetCustomFormsZOrdered(Index: Integer): TCustomForm; begin Result := TCustomForm(FCustomFormsZOrdered[Index]); end; The index variable value is something like 42325 or so. I tried to debug and here is what I found out: It goes through all FormCloseQuesry, FormDestroy and DatamoduleDestory, then it goes to TApplication.DoBeforeFinalization and then into TScreen..GetCustomFormsZOrdered where it fails. I spent days trying to find out where could be the problem but didn't find anything. I'm lost. Do you have any idea where could be a problem, please? Thanks a lot!

Maybe some event uses an already freed object.
Set all references to nil, when freeing objects. For example in TForm1.FormDestroy add Form1:=nil;

And compile with -gh.

Then you can run your program with environment variable HEAPTRC=keepreleased

Mattias

Reply by email

Petr Hlozek
to Mattias Gaertner

Thank you for the help!

I added to all autocreated and used form into OnDestroy what you've writen to me, in Project -> Option -> Debugging checked the -gh option, Run -> Ru parameters in Environment tab added HEAPTRC variable.

After the crash, the callstack window shows

#0 HEAPTRC_TRACEFREEMEMSIZE$POINTER$QWORD$$QWORD at :0

When I click to View source, it jumps to the top of the heaptrc unit.

When I run the app from terminal with environment variable set, I got this:

An unhandled exception occurred at $000000000044139A : EAccessViolation :
$000000000044139A
$00000000005DDD29

The same like before :(

Petr

2014-06-27 11:55 GMT+02:00 Mattias Gaertner :

Show quoted text 42 lines
On Fri, 27 Jun 2014 11:33:53 +0200 Petr Hlozek wrote: > Hi, > > I have an Linux app, it has over 76k lines of code, 78 Forms and uses threads. > After I close the app, it always crashes in > > function TScreen.GetCustomFormsZOrdered(Index: Integer): TCustomForm; > begin > Result := TCustomForm(FCustomFormsZOrdered[Index]); > end; > > The index variable value is something like 42325 or so. > > I tried to debug and here is what I found out: > > It goes through all FormCloseQuesry, FormDestroy and > DatamoduleDestory, then it goes to > TApplication.DoBeforeFinalization and then into > TScreen..GetCustomFormsZOrdered where it fails. > I spent days trying to find out where could be the problem but didn't > find anything. I'm lost. Do you have any idea where could be a > problem, please? Thanks a lot! Maybe some event uses an already freed object. Set all references to nil, when freeing objects. For example in TForm1.FormDestroy add Form1:=nil; And compile with -gh. Then you can run your program with environment variable HEAPTRC=keepreleased Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Petr Hlozek
Show quoted text 10 lines
Thank you for the help! I added to all autocreated and used form into OnDestroy what you've writen to me, in Project -> Option -> Debugging checked the -gh option, Run -> Ru parameters in Environment tab added HEAPTRC variable. After the crash, the callstack window shows #0 HEAPTRC_TRACEFREEMEMSIZE$POINTER$QWORD$$QWORD at :0

This could mean that you double free an object/record. Make sure all references become nil when an object is freed.

When I click to View source, it jumps to the top of the heaptrc unit.

If there are other lines (not #0, but #1, #2, ...) click on them.

Show quoted text 8 lines
When I run the app from terminal with environment variable set, I got this: An unhandled exception occurred at $000000000044139A : EAccessViolation : $000000000044139A $00000000005DDD29 The same like before :(

Something destroys your heap.
Have you tried gdb?

Heaptrc has some more options.

Mattias

Reply by email

Petr Hlozek
to Mattias Gaertner
Show quoted text 11 lines
> I added to all autocreated and used form into OnDestroy what you've > writen to me, in Project -> Option -> Debugging checked the -gh > option, Run -> Ru parameters in Environment tab added HEAPTRC > variable. > > After the crash, the callstack window shows > > #0 HEAPTRC_TRACEFREEMEMSIZE$POINTER$QWORD$$QWORD at :0 This could mean that you double free an object/record. Make sure all references become nil when an object is freed.

I'd like to do that and hopefuly already did but the app is quite big and I'm not sure fo 100%. Is there any way how to find out with any utility?

> When I click to View source, it jumps to the top of the heaptrc unit. If there are other lines (not #0, but #1, #2, ...) click on them.

There is only #1 line with this:
#1 ?? at :0

Nothing more.

Show quoted text 13 lines
> When I run the app from terminal with environment variable set, I got this: > > An unhandled exception occurred at $000000000044139A : > EAccessViolation : > $000000000044139A > $00000000005DDD29 > > The same like before :( Something destroys your heap. Have you tried gdb? Heaptrc has some more options.

I trid also gdb but I'm not so keen with it. When I tried bt after it crashed, I got this:

Program received signal SIGSEGV, Segmentation fault. 0x000000000044139a in HEAPTRC_TRACEFREEMEMSIZE$POINTER$QWORD$$QWORD () (gdb) bt
#0 0x000000000044139a in HEAPTRC_TRACEFREEMEMSIZE$POINTER$QWORD$$QWORD () #1 0x0000000000000000 in ?? ()
(gdb)

Petr

Reply by email

Hans-Peter Diettrich
to Petr Hlozek
I'd like to do that and hopefuly already did but the app is quite big and I'm not sure fo 100%. Is there any way how to find out with any utility?

FastMM4 can do that with Delphi, dunno about an FPC version. It can detect references to already destroyed objects, as well as objects not released when the program terminates.

DoDi

Reply by email