소스 검색

Avoid NRE when disconnecting or disposing.

drieseng 9 년 전
부모
커밋
3cf6979943
1개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 6 5
      src/Renci.SshNet/SftpClient.cs

+ 6 - 5
src/Renci.SshNet/SftpClient.cs

@@ -2128,11 +2128,11 @@ namespace Renci.SshNet
 
             // disconnect, dispose and dereference the SFTP session since we create a new SFTP session
             // on each connect
-            if (_sftpSession != null)
+            var sftpSession = _sftpSession;
+            if (sftpSession != null)
             {
-                _sftpSession.Disconnect();
-                _sftpSession.Dispose();
                 _sftpSession = null;
+                sftpSession.Dispose();
             }
         }
 
@@ -2146,10 +2146,11 @@ namespace Renci.SshNet
 
             if (disposing)
             {
-                if (_sftpSession != null)
+                var sftpSession = _sftpSession;
+                if (sftpSession != null)
                 {
-                    _sftpSession.Dispose();
                     _sftpSession = null;
+                    sftpSession.Dispose();
                 }
             }
         }