Unsubscribe from events before disposing WaitHandles.

This reduces the likelyhood of invoking Set() on a disposed WaitHandle.
Incomplete fix for issues #1944 and #1942 as eventhandlers could still be invoked after unsubscription.
This commit is contained in:
Gert Driesen
2014-04-10 19:00:40 +00:00
parent 0a8ac33d46
commit d3f750aa79
+8 -6
View File
@@ -671,8 +671,16 @@ namespace Renci.SshNet
{
base.Dispose(disposing);
if (this._session != null)
{
this._session.Disconnected -= Session_Disconnected;
this._session.ErrorOccured -= Session_ErrorOccured;
}
if (this._channel != null)
{
this._channel.DataReceived -= Channel_DataReceived;
this._channel.Closed -= Channel_Closed;
this._channel.Dispose();
this._channel = null;
}
@@ -682,12 +690,6 @@ namespace Renci.SshNet
this._dataReceived.Dispose();
this._dataReceived = null;
}
if (this._session != null)
{
this._session.Disconnected -= Session_Disconnected;
this._session.ErrorOccured -= Session_ErrorOccured;
}
}
/// <summary>