The SshCommand class leaves the unerlying channel subscribed to the session events after running a command.
Repro is:
```
using (var client = new SshClient(connectionInfo))
{
client.Connect();
for (var i = 0; i < 100; ++i)
{
// Inspect client.Session.ErrorOccured.GetInvocationList()
using (var cmd = client.CreateCommand("echo hi"))
{
cmd.Execute();
}
// Inspect client.Session.ErrorOccured.GetInvocationList()
// Invocation list is one greater than before.
}
var after = GetEventCount(client);
Assert.AreEqual(before, after);
}
```
It looks like the bug is in SshCommand.EndExecute where this._channel is set to null without being disposed. A proposed fix is attached.
Comments: ** Comment from web user: drieseng **
Repro is:
```
using (var client = new SshClient(connectionInfo))
{
client.Connect();
for (var i = 0; i < 100; ++i)
{
// Inspect client.Session.ErrorOccured.GetInvocationList()
using (var cmd = client.CreateCommand("echo hi"))
{
cmd.Execute();
}
// Inspect client.Session.ErrorOccured.GetInvocationList()
// Invocation list is one greater than before.
}
var after = GetEventCount(client);
Assert.AreEqual(before, after);
}
```
It looks like the bug is in SshCommand.EndExecute where this._channel is set to null without being disposed. A proposed fix is attached.
Comments: ** Comment from web user: drieseng **
Thanks for the report, and the patch!
Fix is committed in changeset 40527.
I also did some refactoring in previous changesets to allow us to unit test the fix for this issue.