GUAC-1171: Ensure user and session objects are automatically free'd, and that this is documented.

This commit is contained in:
Michael Jumper 2015-07-14 11:02:48 -07:00
parent 46ce69a8a9
commit cdefe52c67
5 changed files with 22 additions and 4 deletions

View File

@ -94,7 +94,8 @@ typedef struct guac_common_ssh_sftp_ls_state {
* guac_common_ssh_destroy_sftp_filesystem().
*
* @param session
* The session to use to provide SFTP.
* The session to use to provide SFTP. This session will automatically be
* destroyed when this filesystem is destroyed.
*
* @param name
* The name to send as the name of the filesystem.

View File

@ -22,6 +22,7 @@
#include "guac_ssh.h"
#include "guac_ssh_key.h"
#include "guac_ssh_user.h"
#include <guacamole/client.h>
#include <libssh2.h>
@ -477,8 +478,17 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client,
}
void guac_common_ssh_destroy_session(guac_common_ssh_session* session) {
/* Disconnect and clean up libssh2 */
libssh2_session_disconnect(session->session, "Bye");
libssh2_session_free(session->session);
/* Destroy associated user */
if (session->user)
guac_common_ssh_destroy_user(session->user);
/* Free all other data */
free(session);
}

View File

@ -91,7 +91,8 @@ void guac_common_ssh_uninit();
* The port to connect to on the given hostname.
*
* @param user
* The user to authenticate as, once connected.
* The user to authenticate as, once connected. This user will be
* automatically destroyed when this session is destroyed.
*
* @return
* A new SSH session if the connection and authentication succeed, or NULL

View File

@ -842,8 +842,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Abort if private key cannot be read */
if (guac_common_ssh_user_import_key(user,
argv[IDX_SFTP_PRIVATE_KEY],
argv[IDX_SFTP_PASSPHRASE]))
argv[IDX_SFTP_PASSPHRASE])) {
guac_common_ssh_destroy_user(user);
return 1;
}
}
@ -880,6 +882,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Fail if SSH connection does not succeed */
if (session == NULL) {
/* Already aborted within guac_common_ssh_create_session() */
guac_common_ssh_destroy_user(user);
return 1;
}

View File

@ -384,8 +384,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Abort if private key cannot be read */
if (guac_common_ssh_user_import_key(user,
argv[IDX_SFTP_PRIVATE_KEY],
argv[IDX_SFTP_PASSPHRASE]))
argv[IDX_SFTP_PASSPHRASE])) {
guac_common_ssh_destroy_user(user);
return 1;
}
}
@ -414,6 +416,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Fail if SSH connection does not succeed */
if (session == NULL) {
/* Already aborted within guac_common_ssh_create_session() */
guac_common_ssh_destroy_user(user);
return 1;
}