diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 9cc85a18..cee1d4d5 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -36,6 +36,7 @@ #include +#include #include #include @@ -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); diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index 932a917d..c68f6d3b 100644 --- a/src/protocols/vnc/vnc.c +++ b/src/protocols/vnc/vnc.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -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;