diff --git a/src/common-ssh/guac_sftp.c b/src/common-ssh/guac_sftp.c index 54cfa804..d82b6a1a 100644 --- a/src/common-ssh/guac_sftp.c +++ b/src/common-ssh/guac_sftp.c @@ -665,24 +665,25 @@ guac_object* guac_common_ssh_create_sftp_filesystem( guac_client* client = session->client; + /* Request SFTP */ + LIBSSH2_SFTP* sftp_session = libssh2_sftp_init(session->session); + if (sftp_session == NULL) { + guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, + "Unable to start SFTP session."); + return NULL; + } + /* Allocate data for SFTP session */ guac_common_ssh_sftp_data* sftp_data = malloc(sizeof(guac_common_ssh_sftp_data)); /* Associate SSH session with SFTP data */ sftp_data->ssh_session = session; + sftp_data->sftp_session = sftp_session; /* Initially upload files to current directory */ strcpy(sftp_data->upload_path, "."); - /* Request SFTP */ - sftp_data->sftp_session = libssh2_sftp_init(session->session); - if (sftp_data->sftp_session == NULL) { - guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, - "Unable to start SFTP session."); - return NULL; - } - /* Init filesystem */ guac_object* filesystem = guac_client_alloc_object(client); filesystem->get_handler = guac_common_ssh_sftp_get_handler; diff --git a/src/common-ssh/guac_ssh.c b/src/common-ssh/guac_ssh.c index 7bbd789d..9fcbad50 100644 --- a/src/common-ssh/guac_ssh.c +++ b/src/common-ssh/guac_ssh.c @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef LIBSSH2_USES_GCRYPT GCRY_THREAD_OPTION_PTHREAD_IMPL; @@ -379,6 +380,7 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client, guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Error parsing given address or port: %s", gai_strerror(retval)); + close(fd); return NULL; } @@ -422,6 +424,7 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client, if (current_address == NULL) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, "Unable to connect to any addresses."); + close(fd); return NULL; } @@ -439,6 +442,7 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client, guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Session allocation failed."); free(common_session); + close(fd); return NULL; } diff --git a/src/common-ssh/guac_ssh_user.c b/src/common-ssh/guac_ssh_user.c index 84aad9c5..c9691b16 100644 --- a/src/common-ssh/guac_ssh_user.c +++ b/src/common-ssh/guac_ssh_user.c @@ -48,6 +48,7 @@ void guac_common_ssh_destroy_user(guac_common_ssh_user* user) { /* Free all other data */ free(user->password); free(user->username); + free(user); }