only close once
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ namespace shadowsocks_csharp
|
||||
public byte[] connetionSendBuffer = new byte[BufferSize];
|
||||
// Received data string.
|
||||
public StringBuilder sb = new StringBuilder();
|
||||
private bool closed = false;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
@@ -144,6 +145,11 @@ namespace shadowsocks_csharp
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user