Need help fixing leaks

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need help fixing leaks

leledumbo
Administrator
Could anyone please help me fixing leaks in my project?
This is the output when I debug in gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
#1  0x00406c32 in SYSTEM_TOBJECT_$__FREE ()
#2  0x0040d916 in TFPGOBJECTLIST$TLLVMVALUE__DEREF (ITEM=0x55138,
    this=<error reading variable>) at llvmirbuilder.pp:362
#3  0x00421451 in FGL_TFPSLIST_$__DEREF$LONGINT$LONGINT ()
#4  0x00000000 in ?? ()

That line is the end of a method and I have no idea why the item got dereferenced.
Reply | Threaded
Open this post in threaded view
|

Re: Need help fixing leaks

Jonas Maebe-2

On 21 Dec 2010, at 04:33, leledumbo wrote:

Could anyone please help me fixing leaks in my 
http://free-pascal-general.1045716.n5.nabble.com/file/n3312878/llvmirbuilder.zip
project ?
This is the output when I debug in gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
#1  0x00406c32 in SYSTEM_TOBJECT_$__FREE ()
#2  0x0040d916 in TFPGOBJECTLIST$TLLVMVALUE__DEREF (ITEM=0x55138,
   this=<error reading variable>) at llvmirbuilder.pp:362
#3  0x00421451 in FGL_TFPSLIST_$__DEREF$LONGINT$LONGINT ()
#4  0x00000000 in ?? ()

That line is the end of a method and I have no idea why the item got
dereferenced.

If you have access to a Linux or Mac OS X system, you can compile it with -gv and run it under Valgrind. It's very good at finding memory problems. Note that it may also give some false about the use of uninitialised values in some RTL helpers like fpc_pchar_to_shortstr (search for 80808080 in rtl/i386/* to see the routines where this can happen).


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Need help fixing leaks

Thomas Schatzl
In reply to this post by leledumbo
Hi,

On Mon, 20 Dec 2010 19:33:51 -0800 (PST), leledumbo
<[hidden email]> wrote:

> [...]
> Program received signal SIGSEGV, Segmentation fault.
> 0x00000000 in ?? ()
> (gdb) bt
> #0  0x00000000 in ?? ()
> #1  0x00406c32 in SYSTEM_TOBJECT_$__FREE ()
> #2  0x0040d916 in TFPGOBJECTLIST$TLLVMVALUE__DEREF (ITEM=0x55138,
>     this=<error reading variable>) at llvmirbuilder.pp:362
> #3  0x00421451 in FGL_TFPSLIST_$__DEREF$LONGINT$LONGINT ()
> #4  0x00000000 in ?? ()
>
> That line is the end of a method and I have no idea why the item got
> dereferenced.

At least one issue seems to be that all your TFPGObjectLists are owners of
their respective instances. This leads to multiple attempted Free() calls
to the objects in the list. If I am correct, there are/will be up to three
Free() calls for some objects in your example code.

I may be wrong, I did not really debug the code, just from looking at it.

Thomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Need help fixing leaks

leledumbo
Administrator
> At least one issue seems to be that all your TFPGObjectLists are owners of
> their respective instances. This leads to multiple attempted Free() calls
> to the objects in the list. If I am correct, there are/will be up to three
> Free() calls for some objects in your example code.

> I may be wrong, I did not really debug the code, just from looking at it.

Actually, I realize that too. So I'm refactoring the classes now. This is quite difficult since I may generate a constant on the fly (encapsulated by a class) and in other time a reference to an instruction previously created. Who is responsible to free who is the problem.