EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Memory leak in SBChSConvBase

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
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:

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:

            AdditionalFromUCSBuffer := AdditionalFromUCS^;
            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
Posted: 02/19/2014 04:32:45
by Dmytro Bogatskyy (EldoS Corp.)


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



Topic viewed 553 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!