EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Memory leak in SBChSConvBase

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#28448
Posted: 02/18/2014 17:17:49
by Mason Wheeler (Basic support level)
Joined: 02/18/2014
Posts: 3

I just tracked down a memory leak and found it was coming from inside SBChSConvBase.

There are two places in TPlTableCharset.GenerateBackTable where a very similar operation is performed: call GetAdditionalFromUCS, then run an operation on the result that starts like this:

Code
F := PAnsiChar(@(AdditionalFromUCS^[1]));


Unfortunately, the [] operator causes the compiler to insert a hidden call to UniqueString here, but because the string is being referenced by a pointer and not directly, if the reference count for the original string was > 1 a new unique string is created but never cleaned up.

I solved this by defining an AnsiString named AdditionalFromUCSBuffer and replacing the line above, in both places where it's located, with the following:

Code
            AdditionalFromUCSBuffer := AdditionalFromUCS^;
            UniqueString(AdditionalFromUCSBuffer);
            F := PAnsiChar(@(AdditionalFromUCSBuffer[1]));


It could probably be done more simply in a handful of different ways, but this was the one that required the least change to the semantics of the existing code.

This fixed the memory leaks, and I figured I should report it here for you guys.


Mason Wheeler
De Novo Software
#28458
Posted: 02/19/2014 04:32:45
by Dmytro Bogatskyy (EldoS Corp.)

Hello,

Thank you very much for pointing this out. This issue will be fixed in the next build.

Reply

Statistics

Topic viewed 561 times

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




|

Back to top

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

Got it!