EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Memory leaks.. Again

Posted: 06/19/2008 01:48:14
by Scratch  (Standard support level)
Joined: 02/07/2008
Posts: 34

Correct me if i'm wrong, but the next code results a real mess

var h: TElHashFunction;
  [B]ReportMemoryLeaksOnShutdown := True;[/B]
  h := TElHashFunction.Create(SB_ALGORITHM_DGST_SHA256);

After shutdown I get

Unexpected Memory Leak
An unexpected memory leak has occurred. The unexpected small block leaks are:

1 - 12 bytes: TElPKCS11ConsumerCertStorage x 1, TElCustomCryptoProviderOptions x 2
13 - 20 bytes: TList x 7, Unknown x 2
21 - 28 bytes: Unknown x 1
53 - 60 bytes: TElSharedResource x 5, TElCryptoProviderManager x 1
93 - 100 bytes: TElPKCS11CryptoProvider x 1, TElBuiltInCryptoProvider x 1
109 - 116 bytes: TElPKCS11CertStorage x 1
253 - 268 bytes: TElRandom x 1

Posted: 06/19/2008 02:06:54
by Ken Ivanov (Team)

The mentioned leaks are not "real" memory leaks actually. All these objects are created on the very start of the application and do exist until the application is closed. These objects are reported as non-destroyed, but they are actually destroyed by the OS right after the application has been closed.
Posted: 06/19/2008 02:21:09
by Scratch  (Standard support level)
Joined: 02/07/2008
Posts: 34

I do know that any memory leak is being destroyed by OS during app shutdown, however these leaks mess up with the ones that are real. I mean I'd use RegisterExpectedMemoryLeak for such case or just made a true object destruction during finalize. That's my imho, thanks for help.
Posted: 06/25/2008 10:20:19
by Stephane Grobety (Priority Standard support level)
Joined: 04/18/2006
Posts: 174

I'm sorry to jump in but how would that work in case of a dll ?

You see, one of my application is implemented as a group of dlls that are loaded on demand by the main service application. The process is not supposed to be destroyed for weeks but the dll itself is loaded and unloaded many time a day.

It's my understanding that if that memory is assigned every time the module initialization is processed but never destroyed, it WILL leak.
Posted: 06/25/2008 10:50:51
by Eugene Mayevski (Team)

Indeed, there will be problems with this, unless you have a set of BPLs and one of the BPLs is loaded all the time.

The "leaks" are not easily fixable because of pascal compiler design. The finalization section of the unit is sometimes executed before the object is released by the secondary threads. This causes AVs on unloading of the application. The only solution is not to delete those objects at all. The other possible solution would be to use reference counting on the global objects, but such approach, if implemented, would slow down operations dramatically (because the global objects that we are talking about are the cryptoproviders, via which all cryptography is used).

Sincerely yours
Eugene Mayevski
Posted: 06/25/2008 11:18:20
by Stephane Grobety (Priority Standard support level)
Joined: 04/18/2006
Posts: 174

Indeed I understand.

Would it be possible to have a "cleanup" function that I could call before unloading the dll ? I can do reference counting from the calling app without any problem as there is a single loaded instance per thread and I'm already handling shared resources for these.

Thank you,
Posted: 06/25/2008 11:34:38
by Eugene Mayevski (Team)

Yes, Cleanup procedure in some form will probably be the easiest variant. Or we could hook on DLLUnload, but I don't know at the moment if this is possible.
I will tell the developers to introduce such function.

Sincerely yours
Eugene Mayevski
Posted: 06/26/2008 01:41:15
by Stephane Grobety (Priority Standard support level)
Joined: 04/18/2006
Posts: 174

Thank you, that would be very good.
Posted: 05/11/2010 13:57:29
by miguel erill (Standard support level)
Joined: 05/10/2010
Posts: 3

There has been a long time from the last reply. Does such a cleaning function exist up to date in 8.x releaso of the components?. I am having the same 'leak' problems.


EDIT: Again I reply myself. I found that a BUtils.CleanupRegisteredGlobalObjects()function has been implemented just for this purpose. Thanks for that.
Posted: 05/11/2010 15:24:26
by Ken Ivanov (Team)

Just wish to confirm that you have found the right function.



Topic viewed 3179 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!