Repository: incubator-guacamole-server
Updated Branches:
  refs/heads/master f23133043 -> c344aa854


GUACAMOLE-222: Ensure files downloaded via SFTP are explicitly closed upon 
completion.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/58b85da8
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/58b85da8
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/58b85da8

Branch: refs/heads/master
Commit: 58b85da8f26f8e61036783fe46215caaf50562c7
Parents: 077cc84
Author: Michael Jumper <[email protected]>
Authored: Fri Nov 4 20:44:45 2016 -0700
Committer: Michael Jumper <[email protected]>
Committed: Sun Feb 26 14:11:42 2017 -0800

----------------------------------------------------------------------
 src/common-ssh/guac_sftp.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/58b85da8/src/common-ssh/guac_sftp.c
----------------------------------------------------------------------
diff --git a/src/common-ssh/guac_sftp.c b/src/common-ssh/guac_sftp.c
index e7314d2..953bfd6 100644
--- a/src/common-ssh/guac_sftp.c
+++ b/src/common-ssh/guac_sftp.c
@@ -373,18 +373,29 @@ static int guac_common_ssh_sftp_ack_handler(guac_user* 
user,
 
         }
 
-        /* If EOF, send end */
-        else if (bytes_read == 0) {
-            guac_user_log(user, GUAC_LOG_DEBUG, "File sent");
-            guac_protocol_send_end(user->socket, stream);
-            guac_user_free_stream(user, stream);
-        }
-
-        /* Otherwise, fail stream */
+        /* If bytes could not be read, handle EOF or error condition */
         else {
-            guac_user_log(user, GUAC_LOG_INFO, "Error reading file");
-            guac_protocol_send_end(user->socket, stream);
-            guac_user_free_stream(user, stream);
+
+            /* If EOF, send end */
+            if (bytes_read == 0) {
+                guac_user_log(user, GUAC_LOG_DEBUG, "File sent");
+                guac_protocol_send_end(user->socket, stream);
+                guac_user_free_stream(user, stream);
+            }
+
+            /* Otherwise, fail stream */
+            else {
+                guac_user_log(user, GUAC_LOG_INFO, "Error reading file");
+                guac_protocol_send_end(user->socket, stream);
+                guac_user_free_stream(user, stream);
+            }
+
+            /* Close file */
+            if (libssh2_sftp_close(file) == 0)
+                guac_user_log(user, GUAC_LOG_DEBUG, "File closed");
+            else
+                guac_user_log(user, GUAC_LOG_INFO, "Unable to close file");
+
         }
 
         guac_socket_flush(user->socket);

Reply via email to