Skip to content

Commit 3cf6979

Browse files
committed
Avoid NRE when disconnecting or disposing.
1 parent 76fdef9 commit 3cf6979

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Renci.SshNet/SftpClient.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,11 +2128,11 @@ protected override void OnDisconnecting()
21282128

21292129
// disconnect, dispose and dereference the SFTP session since we create a new SFTP session
21302130
// on each connect
2131-
if (_sftpSession != null)
2131+
var sftpSession = _sftpSession;
2132+
if (sftpSession != null)
21322133
{
2133-
_sftpSession.Disconnect();
2134-
_sftpSession.Dispose();
21352134
_sftpSession = null;
2135+
sftpSession.Dispose();
21362136
}
21372137
}
21382138

@@ -2146,10 +2146,11 @@ protected override void Dispose(bool disposing)
21462146

21472147
if (disposing)
21482148
{
2149-
if (_sftpSession != null)
2149+
var sftpSession = _sftpSession;
2150+
if (sftpSession != null)
21502151
{
2151-
_sftpSession.Dispose();
21522152
_sftpSession = null;
2153+
sftpSession.Dispose();
21532154
}
21542155
}
21552156
}

0 commit comments

Comments
 (0)