From cf8ec8dbc24af6ebc0fd50914405a240c022fbfe Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 25 May 2013 23:05:58 -0700 Subject: [PATCH] Properly cleanup SSH sessions. --- protocols/ssh/src/guac_handlers.c | 12 ++++++++++++ protocols/ssh/src/ssh_client.c | 17 ++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/protocols/ssh/src/guac_handlers.c b/protocols/ssh/src/guac_handlers.c index 99896887..de658067 100644 --- a/protocols/ssh/src/guac_handlers.c +++ b/protocols/ssh/src/guac_handlers.c @@ -49,6 +49,8 @@ #include #include +#include + #include "guac_handlers.h" #include "client.h" #include "common.h" @@ -383,10 +385,20 @@ int ssh_guac_client_free_handler(guac_client* client) { ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data; + /* Close SSH channel */ + ssh_channel_close(guac_client_data->term_channel); + ssh_channel_send_eof(guac_client_data->term_channel); + /* Free terminal */ guac_terminal_free(guac_client_data->term); pthread_join(guac_client_data->client_thread, NULL); + /* Free channels */ + ssh_channel_free(guac_client_data->term_channel); + + /* Free session */ + ssh_free(guac_client_data->session); + /* Free clipboard data */ free(guac_client_data->clipboard_data); diff --git a/protocols/ssh/src/ssh_client.c b/protocols/ssh/src/ssh_client.c index 5f304a04..a0fa9810 100644 --- a/protocols/ssh/src/ssh_client.c +++ b/protocols/ssh/src/ssh_client.c @@ -44,6 +44,8 @@ #include #include +#include + #include "client.h" #include "common.h" @@ -223,18 +225,15 @@ void* ssh_client_thread(void* data) { if ((bytes_read = channel_read(client_data->term_channel, buffer, sizeof(buffer), 0)) == SSH_AGAIN) continue; - if (bytes_read > 0) - guac_terminal_write_all(stdout_fd, buffer, bytes_read); + /* Attempt to write data received. Exit on failure. */ + if (bytes_read > 0) { + int written = guac_terminal_write_all(stdout_fd, buffer, bytes_read); + if (written < 0) + break; + } } - /* Notify on error */ - if (bytes_read < 0) { - guac_protocol_send_error(socket, "Error reading data."); - guac_socket_flush(socket); - return NULL; - } - /* Wait for input thread to die */ pthread_join(input_thread, NULL);