Recent

Author Topic: Memory leak reported without any line number or unit name  (Read 611 times)

ertank

  • Sr. Member
  • ****
  • Posts: 266
Memory leak reported without any line number or unit name
« on: July 07, 2020, 06:02:17 am »
Hello,

I am using fpc v3.2.1 from fixes branch compiled on 4th of July. Lazarus v2.0.11 from fixes branch compiled on same day as fpc using fpcupdeluxe.

I have a console application developed on Raspberry Pi.

It uses some of my own utility units (logging etc), some other units collected from internet (binary version extracting), and Indy TCPServer component.

I have a leak reported on exit and there is no line number printed or unit name written in that output.
Code: [Select]
Heap dump by heaptrc unit of /home/pi/test/test
374 memory blocks allocated : 84905/86472
371 memory blocks freed     : 84837/86392
3 unfreed memory blocks : 68
True heap size : 294912
True free heap : 294496
Should be : 294544
Call trace for block $B6F2F3E0 size 28
  $00110118
  $00033400
Call trace for block $B6D3EE00 size 12
  $00110118
  $00033400
Call trace for block $B6F2F2C0 size 28
  $00033400
  $000384D8

I have already tried to remark some "create" lines but that is not helping. I constantly seem to get that leak reported. As far as I can tell, I am freeing anything I create. There is below initialization line in my logging unit. I do not think that maybe the problem.
Code: [Select]
// LogFilename is a string variable
initialization
  LogFilename := ExtractFilePath(ParamStr(0)) + 'log/' + FormatDateTime('yyyy-mm', Now()) + '.log';

I wonder if it is in anyway possible to find out where exactly these blocks are allocated? I basically have Lazarus on that Raspberry Pi and nothing else. I am open to installing necessary tools.

Internet searches are not in my favor today.

Any help is appreciated.

Thanks & Regards,
Ertan

totya

  • Hero Member
  • *****
  • Posts: 632
Re: Memory leak reported without any line number or unit name
« Reply #1 on: July 07, 2020, 06:16:06 am »
Usually under app development strongly recommended always compile to debugmode (with heptrc). In this way, you always see if memory leak present, and the reason certainly the last writed code. Without it very hard to find the problematic code..

ertank

  • Sr. Member
  • ****
  • Posts: 266
Re: Memory leak reported without any line number or unit name
« Reply #2 on: July 07, 2020, 07:05:22 am »
This is relatively new project.

I removed all units from uses. Removed lines they are used. Kept only IdTCPServer, IdGlobal units and TIdTCPServer component variable.

I did not activate TIdTCPComponent. No OnExecute event is assigned to it. Just Created TIdTCPServer class and freed it.

Still there is 68 bytes of memory leaking.

I am going to try a new project to replicate.

ertank

  • Sr. Member
  • ****
  • Posts: 266
Re: Memory leak reported without any line number or unit name
« Reply #3 on: July 07, 2020, 07:26:27 am »
It seems there is a small memory leak in below commit of Indy on Raspberry Pi (Linux-ARM) systems.
Code: [Select]
commit c8220089c2509b707ca90f0d0a5d5893f213584b (grafted, HEAD -> master, origin/master, origin/HEAD)
Author: Remy Lebeau <remy@lebeausoftware.org>
Date:   Wed Jun 24 10:13:47 2020 -0700

Leak happens just by including IdTCPServer in uses list. It is not necessary to create TIdTCPServer or any other object.

When I check IdTCPServer.pas I did not see any initialization section. Going a little deeper, leak maybe in one of the below files by first sight.
Code: [Select]
  IdResourceStringsCore,
  IdBaseComponent,
  IdComponent,
  IdContext,
  IdGlobal,
  IdException,
  IdIntercept,
  IdIOHandler,
  IdIOHandlerStack,
  IdReply,
  IdScheduler,
  IdSchedulerOfThread,
  IdServerIOHandler,
  IdServerIOHandlerStack,
  IdSocketHandle,
  IdStackConsts,
  IdTCPConnection,
  IdThread,
  IdYarn,
  IdGlobalCore,
  IdResourceStringsCore,
  IdReplyRFC,
  IdSchedulerOfThreadDefault,
  IdStack,
  IdThreadSafe

I do not know design details of Indy and so I did not go deeper than above myself. It is possible leak is deep in somewhere else. If anybody has some knowledge about Indy design and have some time he/she is welcome to check it out.

Thanks & Regards,
Ertan

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

ertank

  • Sr. Member
  • ****
  • Posts: 266
Re: Memory leak reported without any line number or unit name
« Reply #5 on: July 07, 2020, 10:05:17 pm »
Changing compile time parameter did not help me to get rid of that leak.

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: Memory leak reported without any line number or unit name
« Reply #6 on: July 07, 2020, 10:43:13 pm »
look here: https://forum.lazarus.freepascal.org/index.php/topic,39257.msg268869.html#msg268869
These two global objects are intentionally leaked by default, but the leaks can be disabled by re-compiling Indy with FREE_ON_FINAL enabled (but do read the warnings documented at the very bottom of those units' source code).
How Remy said, you must recompile Indy

Or you can ignore these 3 leaks.
« Last Edit: July 07, 2020, 10:44:45 pm by sstvmaster »
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

ertank

  • Sr. Member
  • ****
  • Posts: 266
Re: Memory leak reported without any line number or unit name
« Reply #7 on: July 08, 2020, 11:01:43 am »
I'll leave with that three leaks for now. Thanks.

 

TinyPortal © 2005-2018