diff --git a/src/protocols/ssh/client.c b/src/protocols/ssh/client.c index 7b31e82c..b3c5bf26 100644 --- a/src/protocols/ssh/client.c +++ b/src/protocols/ssh/client.c @@ -162,6 +162,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->enable_sftp = strcmp(argv[IDX_ENABLE_SFTP], "true") == 0; client_data->sftp_session = NULL; client_data->sftp_ssh_session = NULL; + client_data->sftp_filesystem = NULL; strcpy(client_data->sftp_upload_path, "."); #ifdef ENABLE_SSH_AGENT diff --git a/src/protocols/ssh/client.h b/src/protocols/ssh/client.h index 596f72fd..39d8d544 100644 --- a/src/protocols/ssh/client.h +++ b/src/protocols/ssh/client.h @@ -132,7 +132,7 @@ typedef struct ssh_guac_client_data { /** * The filesystem object exposed for the SFTP session. */ - guac_object* filesystem; + guac_object* sftp_filesystem; /** * The path files will be sent to, if uploaded directly via a "file" diff --git a/src/protocols/ssh/guac_handlers.c b/src/protocols/ssh/guac_handlers.c index 28e86213..ea01e884 100644 --- a/src/protocols/ssh/guac_handlers.c +++ b/src/protocols/ssh/guac_handlers.c @@ -101,15 +101,20 @@ int ssh_guac_client_free_handler(guac_client* client) { /* Free channels */ libssh2_channel_free(guac_client_data->term_channel); - /* Clean up SFTP */ + /* Shutdown SFTP session, if any */ if (guac_client_data->sftp_session) libssh2_sftp_shutdown(guac_client_data->sftp_session); + /* Disconnect SSH session corresponding to the SFTP session */ if (guac_client_data->sftp_ssh_session) { libssh2_session_disconnect(guac_client_data->sftp_ssh_session, "Bye"); libssh2_session_free(guac_client_data->sftp_ssh_session); } + /* Clean up the SFTP filesystem object */ + if (guac_client_data->sftp_filesystem) + guac_client_free_object(client, guac_client_data->sftp_filesystem); + /* Free session */ if (guac_client_data->session != NULL) libssh2_session_free(guac_client_data->session); diff --git a/src/protocols/ssh/sftp.h b/src/protocols/ssh/sftp.h index b9e406e7..73cc9f4e 100644 --- a/src/protocols/ssh/sftp.h +++ b/src/protocols/ssh/sftp.h @@ -108,7 +108,9 @@ guac_stream* guac_sftp_download_file(guac_client* client, char* filename); void guac_sftp_set_upload_path(guac_client* client, char* path); /** - * Exposes access to SFTP via a filesystem object, returning that object. + * Exposes access to SFTP via a filesystem object, returning that object. The + * object returned must eventually be explicitly freed through a call to + * guac_client_free_object(). * * @param client * The Guacamole client to expose the filesystem to. diff --git a/src/protocols/ssh/ssh_client.c b/src/protocols/ssh/ssh_client.c index b1afbf34..24f5fd8d 100644 --- a/src/protocols/ssh/ssh_client.c +++ b/src/protocols/ssh/ssh_client.c @@ -477,7 +477,7 @@ void* ssh_client_thread(void* data) { client->file_handler = guac_sftp_file_handler; /* Expose filesystem */ - guac_sftp_expose_filesystem(client); + client_data->sftp_filesystem = guac_sftp_expose_filesystem(client); guac_client_log(client, GUAC_LOG_DEBUG, "SFTP session initialized");