Browse Source

When ChannelDirectTcpip Close method is called, make sure Socket is closed too.

olegkap_cp 13 years ago
parent
commit
3581389dd6

+ 13 - 2
Renci.SshClient/Renci.SshNet/Channels/ChannelDirectTcpip.cs

@@ -129,8 +129,12 @@ namespace Renci.SshNet.Channels
             //  If listener thread is finished then socket was closed
             System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof, readerTaskCompleted });
 
-            this._socket.Dispose();
-            this._socket = null;
+            //  Close socket if still open
+            if (this._socket != null)
+            {
+                this._socket.Dispose();
+                this._socket = null;
+            }
 
             if (exception != null)
                 throw exception;
@@ -138,6 +142,13 @@ namespace Renci.SshNet.Channels
 
         public override void Close()
         {
+            //  Close socket if still open
+            if (this._socket != null)
+            {
+                this._socket.Dispose();
+                this._socket = null;
+            }
+
             //  Send EOF message first when channel need to be closed
             this.SendMessage(new ChannelEofMessage(this.RemoteChannelNumber));
 

+ 3 - 0
Renci.SshClient/Renci.SshNet/Common/Extensions.cs

@@ -187,6 +187,9 @@ namespace Renci.SshNet
             if (value == null)
                 return false;
 
+            if (value == string.Empty)
+                return true;
+
             if (_rehost.Match(value).Success)
                 return true;