Sign in Join

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

Mailing lists / lazarus / 2016-06

Memory leak with Synchronize on external threads

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Stefan Schalk

Hi Sven,

many thanks for your quick response and solution!

I tried the new FPC sources (Revision 33878) and ran in a segmentation fault. In classes.inc line 345 the SizeOf gets the length from the pointer but I think the length of the structure is needed:

    currently: FillChar(syncentry^, SizeOf(syncentry), 0);
    suggestion: FillChar(syncentry^, SizeOf(TThreadQueueEntry), 0);

Because of that, the uninitialized structure member "Next" will lead to a segmentation fault afterwards.
I tried the suggestion and everything works fine (no SIGSEGV, no memory leak). Can you please review my suggestion?

Best regards,
Stefan

Earlier message 22 lines
-----Ursprüngliche Nachricht----- Von: Lazarus [mailto:] Im Auftrag von Sven Barth Gesendet: Dienstag, 31. Mai 2016 22:22 An: Betreff: Re: [Lazarus] Memory leak with Synchronize on external threads I've committed a fix in FPC revision 33863 and if all goes well it should be merged to 3.0.1 as well, thus becoming part of 3.0.2. A check with Delphi has shown that the WakeMainThread event gets Nil as Sender argument with an external thread, so I can avoid the use of CurrentThread which triggered the memory usage. Please note that this is however not a leak as CurrentThread will create a TExternalThread instance for a thread that hasn't been created by TThread (and for which no instance exists yet) and this instance must (sadly) be kept around until the program terminates. Regards, Sven --

Reply by email

Sven Barth
to Stefan Schalk
"Stefan Schalk" wrote 7 lines
Hi Sven, many thanks for your quick response and solution! I tried the new FPC sources (Revision 33878) and ran in a segmentation

fault.

In classes.inc line 345 the SizeOf gets the length from the pointer but I

think

Show quoted text 9 lines
the length of the structure is needed: currently: FillChar(syncentry^, SizeOf(syncentry), 0); suggestion: FillChar(syncentry^, SizeOf(TThreadQueueEntry), 0); Because of that, the uninitialized structure member "Next" will lead to a segmentation fault afterwards. I tried the suggestion and everything works fine (no SIGSEGV, no memory

leak).

Can you please review my suggestion?

You're indeed right. Fixed that.

Though this whole fix won't be part of 3.0.2 anymore as it got discovered (and fixed) too late.

As a workaround try to avoid calling Synchronize from a new external thread each time. If it is the same thread then memory usage won't increase after the first call.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160605/3756d860/attachment.html>

Reply by email