From 8285af7ea4bb701a9e6720ffa1742df4003b0529 Mon Sep 17 00:00:00 2001
From: Ulrich Sibiller <uli42@gmx.de>
Date: Fri, 17 May 2019 22:41:37 +0200
Subject: [PATCH 2/2] checkLogin(): close channel on failure

---
 src/sshmasterconnection.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 141de4c..cde33ba 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1654,6 +1654,7 @@ bool SshMasterConnection::checkLogin()
         QString err=ssh_get_error ( my_ssh_session );
         QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_open_session");
         x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        ssh_channel_free(channel);
         return false;
     }
     if (ssh_channel_request_pty(channel)!=SSH_OK)
@@ -1661,6 +1662,7 @@ bool SshMasterConnection::checkLogin()
         QString err=ssh_get_error ( my_ssh_session );
         QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_request_pty");
         x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        ssh_channel_free(channel);
         return false;
     }
     if(ssh_channel_change_pty_size(channel, 80, 24)!=SSH_OK)
@@ -1668,6 +1670,7 @@ bool SshMasterConnection::checkLogin()
         QString err=ssh_get_error ( my_ssh_session );
         QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_change_pty_size");
         x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        ssh_channel_free(channel);
         return false;
     }
     if ( ssh_channel_request_exec ( channel, "echo \"LOGIN OK\"" ) != SSH_OK )
@@ -1675,6 +1678,7 @@ bool SshMasterConnection::checkLogin()
         QString err=ssh_get_error ( my_ssh_session );
         QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_request_exec");
         x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        ssh_channel_free(channel);
     }
     else
     {
@@ -1687,7 +1691,10 @@ bool SshMasterConnection::checkLogin()
         {
             int nbytes = ssh_channel_read_nonblocking(channel, buffer, sizeof(buffer), 0);
             if (nbytes < 0)
+            {
+                ssh_channel_free(channel);
                 return false;
+            }
             if (nbytes > 0)
             {
                 QString inf=QByteArray ( buffer,nbytes );
-- 
2.11.0

