From 9f82f4bb4d6c47da160853288d771f1c32f937ec Mon Sep 17 00:00:00 2001 From: olegkap_cp Date: Fri, 10 Feb 2012 18:41:39 +0000 Subject: [PATCH] Replace Dispose with Clear to make it compilable in Mono Fix posible memory leak in HMac --- .../Security/Cryptography/DsaDigitalSignature.cs | 2 +- .../Renci.SshNet/Security/Cryptography/HMAC.cs | 11 +++++++++++ Renci.SshClient/Renci.SshNet/Session.cs | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs b/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs index aebf86d3..87cdc506 100644 --- a/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs +++ b/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs @@ -164,7 +164,7 @@ namespace Renci.SshNet.Security.Cryptography // Dispose managed ResourceMessages. if (this._hash != null) { - this._hash.Dispose(); + this._hash.Clear(); this._hash = null; } } diff --git a/Renci.SshClient/Renci.SshNet/Security/Cryptography/HMAC.cs b/Renci.SshClient/Renci.SshNet/Security/Cryptography/HMAC.cs index f0457357..8152ff6d 100644 --- a/Renci.SshClient/Renci.SshNet/Security/Cryptography/HMAC.cs +++ b/Renci.SshClient/Renci.SshNet/Security/Cryptography/HMAC.cs @@ -153,5 +153,16 @@ namespace Renci.SshNet.Security.Cryptography this._outerPadding[i] ^= this.KeyValue[i]; } } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (this._hash != null) + { + this._hash.Clear(); + this._hash = null; + } + } } } diff --git a/Renci.SshClient/Renci.SshNet/Session.cs b/Renci.SshClient/Renci.SshNet/Session.cs index b4d6a646..56446e2b 100644 --- a/Renci.SshClient/Renci.SshNet/Session.cs +++ b/Renci.SshClient/Renci.SshNet/Session.cs @@ -1218,13 +1218,13 @@ namespace Renci.SshNet // Dispose of old ciphers and hash algorithms if (this._serverMac != null) { - this._serverMac.Dispose(); + this._serverMac.Clear(); this._serverMac = null; } if (this._clientMac != null) { - this._clientMac.Dispose(); + this._clientMac.Clear(); this._clientMac = null; }