Properly cleanup SSH sessions.

This commit is contained in:
Michael Jumper 2013-05-25 23:05:58 -07:00
parent 763ed37179
commit cf8ec8dbc2
2 changed files with 20 additions and 9 deletions

View File

@ -49,6 +49,8 @@
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/error.h> #include <guacamole/error.h>
#include <libssh/libssh.h>
#include "guac_handlers.h" #include "guac_handlers.h"
#include "client.h" #include "client.h"
#include "common.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; 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 */ /* Free terminal */
guac_terminal_free(guac_client_data->term); guac_terminal_free(guac_client_data->term);
pthread_join(guac_client_data->client_thread, NULL); 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 clipboard data */
free(guac_client_data->clipboard_data); free(guac_client_data->clipboard_data);

View File

@ -44,6 +44,8 @@
#include <guacamole/protocol.h> #include <guacamole/protocol.h>
#include <guacamole/socket.h> #include <guacamole/socket.h>
#include <libssh/libssh.h>
#include "client.h" #include "client.h"
#include "common.h" #include "common.h"
@ -223,16 +225,13 @@ void* ssh_client_thread(void* data) {
if ((bytes_read = channel_read(client_data->term_channel, buffer, sizeof(buffer), 0)) == SSH_AGAIN) if ((bytes_read = channel_read(client_data->term_channel, buffer, sizeof(buffer), 0)) == SSH_AGAIN)
continue; continue;
if (bytes_read > 0) /* Attempt to write data received. Exit on failure. */
guac_terminal_write_all(stdout_fd, buffer, bytes_read); 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 */ /* Wait for input thread to die */