EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TMemoryStream memory leak with TElPGPWriter

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#6448
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

Code
function PGP_Encrypt_string(
            UserName, DataIn: string;
            var PGP_DataOut : string) : boolean;
var
  nb_public,nb_secret,i : integer;
  StreamIn,StreamOut : TMemoryStream;
  Temp_pgpKeyring: TElPGPKeyring;
  Temp_pgpWriter: TElPGPWriter;
begin
  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;
  
  pgpKeyring.ExportTo(Temp_pgpKeyring);

  try
    StreamIn.WriteBuffer(Pointer(DataIn)^,length(DataIn));
    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.Passphrases.Clear();
    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
    begin
      if Temp_pgpKeyring.PublicKeys[i].UserIDs[0].Name = UserName then
      begin
        inc(nb_public);
        SBPGPKeys.TElPGPCustomPublicKey(Temp_pgpKeyring.PublicKeys[i]).Enabled := true;
      end
      else
      begin
        SBPGPKeys.TElPGPCustomPublicKey(Temp_pgpKeyring.PublicKeys[i]).Enabled := false;
      end;
    end;

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

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

      StreamOut.Position := 0;
      SetLength(PGP_DataOut, StreamOut.Size);
      StreamOut.ReadBuffer(Pointer(PGP_DataOut)^,StreamOut.Size);
    end;
    result := true;
  except
    result := false;
  end;

  FreeAndNil(Temp_pgpKeyring);
  FreeAndNil(Temp_pgpWriter);
  StreamIn.Free;
  StreamOut.Free;

end;


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

Thx for your support
#6449
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
#6450
Posted: 05/30/2008 13:35:53
by CHERUBIN Cyril (Standard support level)
Joined: 05/30/2008
Posts: 7

Eugene,

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

and will inform you ASAP
#6454
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 ]
#6455
Posted: 05/31/2008 00:23:00
by Eugene Mayevski (EldoS Corp.)

Moved to HelpDesk for investigation.


Sincerely yours
Eugene Mayevski
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

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