GUAC-1171: Fix resource leaks.

This commit is contained in:
Michael Jumper 2015-07-12 22:19:36 -07:00
parent cc717f4112
commit c6191f4539
3 changed files with 14 additions and 8 deletions

View File

@ -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;

View File

@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#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;
}

View File

@ -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);
}