From 4b32cd8238fea491417ef3fdbfb1e9f97b8453e6 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 12 Sep 2023 19:26:00 +0000 Subject: [PATCH] GUACAMOLE-1846: Skip user promotion entirely if there are no pending users. --- src/libguac/client.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libguac/client.c b/src/libguac/client.c index 51c43c63f2..d490e64387 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -185,24 +185,22 @@ static void guac_client_promote_pending_users(union sigval data) { /* Acquire the lock for reading and modifying the list of pending users */ guac_rwlock_acquire_write_lock(&(client->__pending_users_lock)); + /* Skip user promotion entirely if there's no pending users */ + if (client->__pending_users == NULL) + goto promotion_complete; + /* Run the pending join handler, if one is defined */ if (client->join_pending_handler) { /* If an error occurs in the pending handler */ if(client->join_pending_handler(client)) { - guac_rwlock_release_lock(&(client->__pending_users_lock)); - - /* Mark the handler as not running */ - pthread_mutex_lock(&(client->__pending_users_timer_mutex)); - client->__pending_users_timer_state = GUAC_CLIENT_PENDING_TIMER_REGISTERED; - pthread_mutex_unlock(&(client->__pending_users_timer_mutex)); - /* Log a warning and abort the promotion of the pending users */ guac_client_log(client, GUAC_LOG_WARNING, "join_pending_handler did not successfully complete;" " any pending users have not been promoted.\n"); - return; + + goto promotion_complete; } } @@ -239,6 +237,8 @@ static void guac_client_promote_pending_users(union sigval data) { guac_rwlock_release_lock(&(client->__users_lock)); +promotion_complete: + /* Release the lock (this is done AFTER updating the connected user list * to ensure that all users are always on exactly one of these lists) */ guac_rwlock_release_lock(&(client->__pending_users_lock));