GUACAMOLE-414: Clean up style and move mutex init to client allocation.

This commit is contained in:
Nick Couchman 2019-03-10 17:33:14 -04:00
parent df4c93b3e8
commit 36817f3774
2 changed files with 15 additions and 10 deletions

View File

@ -36,6 +36,7 @@
#include <guacamole/client.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
@ -48,6 +49,11 @@ int guac_client_init(guac_client* client) {
guac_vnc_client* vnc_client = calloc(1, sizeof(guac_vnc_client));
client->data = vnc_client;
#ifdef ENABLE_VNC_TLS_LOCKING
/* Initialize the write lock */
pthread_mutex_init(&(vnc_client->tls_lock), NULL);
#endif
/* Init clipboard */
vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
@ -125,6 +131,11 @@ int guac_vnc_client_free_handler(guac_client* client) {
if (settings != NULL)
guac_vnc_settings_free(settings);
#ifdef ENABLE_VNC_TLS_LOCKING
/* Clean up TLS lock mutex. */
pthread_mutex_destroy(&(vnc_client->tls_lock));
#endif
/* Free generic data struct */
free(client->data);

View File

@ -47,7 +47,6 @@
#include <guacamole/socket.h>
#include <guacamole/timestamp.h>
#include <rfb/rfbclient.h>
#include <rfb/rfbconfig.h>
#include <rfb/rfbproto.h>
#include <stdlib.h>
@ -71,11 +70,11 @@ char* GUAC_VNC_CLIENT_KEY = "GUAC_VNC";
*/
static rfbBool guac_vnc_lock_write_to_tls(rfbClient* rfb_client) {
// Retrieve the Guacamole data structures
/* Retrieve the Guacamole data structures */
guac_client* gc = rfbClientGetClientData(rfb_client, GUAC_VNC_CLIENT_KEY);
guac_vnc_client* vnc_client = (guac_vnc_client*) gc->data;
// Lock write access
/* Lock write access */
int retval = pthread_mutex_lock(&(vnc_client->tls_lock));
if (retval) {
guac_client_log(gc, GUAC_LOG_ERROR, "Error locking TLS write mutex: %d", retval);
@ -100,11 +99,11 @@ static rfbBool guac_vnc_lock_write_to_tls(rfbClient* rfb_client) {
*/
static rfbBool guac_vnc_unlock_write_to_tls(rfbClient* rfb_client) {
// Retrieve the Guacamole data structures
/* Retrieve the Guacamole data structures */
guac_client* gc = rfbClientGetClientData(rfb_client, GUAC_VNC_CLIENT_KEY);
guac_vnc_client* vnc_client = (guac_vnc_client*) gc->data;
// Unlock write access
/* Unlock write access */
int retval = pthread_mutex_unlock(&(vnc_client->tls_lock));
if (retval) {
guac_client_log(gc, GUAC_LOG_ERROR, "Error unlocking TLS write mutex: %d", retval);
@ -247,11 +246,6 @@ void* guac_vnc_client_thread(void* data) {
rfbClientLog = guac_vnc_client_log_info;
rfbClientErr = guac_vnc_client_log_error;
#ifdef ENABLE_VNC_TLS_LOCKING
/* Initialize the write lock */
pthread_mutex_init(&(vnc_client->tls_lock), NULL);
#endif
/* Attempt connection */
rfbClient* rfb_client = guac_vnc_get_client(client);
int retries_remaining = settings->retries;