From 3cf69799437d86305d3079722aedf51b4903fdea Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 11 Sep 2016 20:21:27 +0200 Subject: [PATCH] Avoid NRE when disconnecting or disposing. --- src/Renci.SshNet/SftpClient.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Renci.SshNet/SftpClient.cs b/src/Renci.SshNet/SftpClient.cs index 336cefc2..c98e3fff 100644 --- a/src/Renci.SshNet/SftpClient.cs +++ b/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(); } } }