[fpc-devel] Possible memory leak in cthread.

Michael Van Canneyt michael at freepascal.org
Wed Aug 5 14:53:58 CEST 2009



On Wed, 5 Aug 2009, Jonas Maebe wrote:

>
> On 05 Aug 2009, at 13:55, Wimpie Nortje wrote:
>
>> program memleak;
>> 
>> {$mode objfpc}{$H+}
>> 
>> uses
>> cthreads;
>> 
>> begin
>> end.
>> 
>> If I run the program using valgrind I get the following output:
>> ==1944==    Invalid free() / delete / delete[] 
>> ==1944==    at 0x4025DFA: free (vg_replace_malloc.c:323) 
>> ==1944==    by 0x4171664: (within /lib/tls/i686/cmov/libc-2.9.so)
>> ==1944==    by 0x4020422: _vgnU_freeres (vg_preloaded.c:60)
>> ==1944==    by 0x40E5B23: _Exit (in /lib/tls/i686/cmov/libc-2.9.so)
>> ==1944==    by 0x405C77C: (below main) (in /lib/tls/i686/cmov/libc-2.9.so)
>> ==1944==  Address 0xffffffff is not stack'd, malloc'd or (recently) free'd
>
> This invalid free is probably the reason for the memory leak.
>
> It even happens for this program:
>
> {$linklib c}
> begin
> end.
>
> There is probably some error in FPC's startup code (the code in 
> fpc/rtl/linux/i386/cprt0.as) which doesn't initialise some libc pointer. You 
> should indeed report a bug about this.
>
> To Graeme and Michael: heaptrc is useless/irrelevant to analyse memory leaks 
> reported inside libc. Such errors can always be due to wrong usage of the C 
> library from within FPC code.

Correct.

I just wanted to show that it is not due to FPC reserving some memory and not freeing it.

Michael.



More information about the fpc-devel mailing list