only close once

This commit is contained in:
clowwindy
2014-11-06 01:10:03 +08:00
parent d185481726
commit 5f56ee2d2c
2 changed files with 55 additions and 0 deletions
@@ -211,9 +211,58 @@ namespace shadowsocks_csharp.Encrypt
}
}
#region IDisposable
private bool _disposed;
public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~PolarSSLEncryptor()
{
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
}
if (_encryptCtx != null)
{
switch (_cipher)
{
case CIPHER_AES:
PolarSSL.aes_free(_encryptCtx);
break;
case CIPHER_RC4:
PolarSSL.arc4_free(_encryptCtx);
break;
}
}
if (_decryptCtx != null)
{
switch (_cipher)
{
case CIPHER_AES:
PolarSSL.aes_free(_decryptCtx);
break;
case CIPHER_RC4:
PolarSSL.arc4_free(_decryptCtx);
break;
}
}
_encryptCtx = null;
_decryptCtx = null;
_disposed = true;
}
}
#endregion
}
}