EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TMemoryStream memory leak with TElPGPWriter

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
Posted: 05/30/2008 09:06:46
by CHERUBIN Cyril (Standard support level)
Joined: 05/30/2008
Posts: 7

Hi all,

I'm trying to encrypt in PGP a string : It's working fine BUT
There is a memory leak on TMemoryStream after TElPGPWriter

The global keyring is static in a form = pgpKeyring with OnKeyPassphrase

I'm using temp Keyring to enable only selected user

function PGP_Encrypt_string(
            UserName, DataIn: string;
            var PGP_DataOut : string) : boolean;
  nb_public,nb_secret,i : integer;
  StreamIn,StreamOut : TMemoryStream;
  Temp_pgpKeyring: TElPGPKeyring;
  Temp_pgpWriter: TElPGPWriter;
  nb_public := 0;
  nb_secret := 0;
  result := false;
  StreamIn := TMemoryStream.Create;
  StreamOut := TMemoryStream.Create;
  Temp_pgpKeyring := TElPGPKeyring.Create(nil);
  Temp_pgpWriter := TElPGPWriter.Create(nil);
  Temp_pgpWriter.OnKeyPassphrase := pgpReaderKeyPassphrase;

    StreamIn.Position := 0;

    Temp_pgpWriter.Compress := true;
    Temp_pgpWriter.EncryptingKeys := Temp_pgpKeyring;
    Temp_pgpWriter.SigningKeys := Temp_pgpKeyring;
    Temp_pgpWriter.CompressionLevel := 9;
    Temp_pgpWriter.CompressionAlgorithm := SB_PGP_ALGORITHM_CM_ZLIB;
    Temp_pgpWriter.EncryptionType := etPublicKey;
    Temp_pgpWriter.InputIsText := false;
    Temp_pgpWriter.Protection :=ptHigh;
    Temp_pgpWriter.HashAlgorithm := SB_PGP_ALGORITHM_MD_SHA512;
    Temp_pgpWriter.SymmetricKeyAlgorithm := SB_PGP_ALGORITHM_SK_AES256;
    Temp_pgpWriter.Timestamp := Now;
    Temp_pgpWriter.UseNewFeatures := false;
    Temp_pgpWriter.UseOldPackets := false;

    // select destinataire PublicKeys
    for i := 0 to Temp_pgpKeyring.PublicCount - 1 do
      if Temp_pgpKeyring.PublicKeys[i].UserIDs[0].Name = UserName then
        SBPGPKeys.TElPGPCustomPublicKey(Temp_pgpKeyring.PublicKeys[i]).Enabled := true;
        SBPGPKeys.TElPGPCustomPublicKey(Temp_pgpKeyring.PublicKeys[i]).Enabled := false;

    // select source SecretKeys
    for i := 0 to pgpKeyring.SecretCount - 1 do
      if Temp_pgpKeyring.SecretKeys[i].Enabled then
        SBPGPKeys.TElPGPCustomSecretKey(Temp_pgpKeyring.SecretKeys[i]).Enabled := true;
        SBPGPKeys.TElPGPCustomSecretKey(Temp_pgpKeyring.SecretKeys[i]).Enabled := false;

    if (nb_public=1) and (nb_secret=1) then
      Temp_pgpWriter.EncryptAndSign(StreamIn, StreamOut, 0);

      StreamOut.Position := 0;
      SetLength(PGP_DataOut, StreamOut.Size);
    result := true;
    result := false;



Could you help me to fix memory leak ?
I'm using secbbox for D7

Thx for your support
Posted: 05/30/2008 09:44:04
by Eugene Mayevski (EldoS Corp.)

Unfortunately we don't have technical possibility to fix old versions. First of all, please update your version to build 5.2.124 and see if it solves your problem. Next, use some memory leak detection tool like AQTime or madExcept to localize the source of the leak.

Sincerely yours
Eugene Mayevski
Posted: 05/30/2008 13:35:53
by CHERUBIN Cyril (Standard support level)
Joined: 05/30/2008
Posts: 7


ok I will update with Version 6.0.142. Released on 2008-05-30

and will inform you ASAP
Posted: 05/30/2008 16:20:53
by CHERUBIN Cyril (Standard support level)
Joined: 05/30/2008
Posts: 7

I updated my SBB version with v6.0.142

I built a mod version of Samples\OpenPGP\Primitives\EncryptAndSign
added a loop encryption & sign action on a file with a precook passphrase

And bad news, it's the same.

On a file 30Ko
Begin Mem Usage = 22 068 Ko
After 100 loops = 23 028 Ko
After 1000 loops = 32 232 Ko
+ 10 Mo !!!

You will find enclosed source code
You just have to :
- setup the passphrase at the end of the code
- setup the license key in TElSBLicenseManager

Could you find where is the memory leak ?
in this code or in SBB ?

Thx for your feed back

[ Download ]
Posted: 05/31/2008 00:23:00
by Eugene Mayevski (EldoS Corp.)

Moved to HelpDesk for investigation.

Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.



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