From e3adb970851168571c7753d86b6f8bd109dc0503 Mon Sep 17 00:00:00 2001 From: Mike Jumper Date: Mon, 28 Nov 2022 13:37:39 -0800 Subject: [PATCH] GUACAMOLE-1293: Do not re-acquire __users_lock while already held for writing. Per POSIX spec, the behavior of acquiring a read lock on a rwlock that's already acquired for writing is undefined. From the documentation for pthread_rwlock_rdlock(): "... Results are undefined if the calling thread holds a write lock on rwlock at the time the call is made." --- 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 29fb5b78..952ffcc3 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -302,15 +302,15 @@ int guac_client_add_user(guac_client* client, guac_user* user, int argc, char** /* Update owner pointer if user is owner */ if (user->owner) client->__owner = user; - - /* Notify owner of user joining connection. */ - else - guac_client_owner_notify_join(client, user); } pthread_rwlock_unlock(&(client->__users_lock)); + /* Notify owner of user joining connection. */ + if (retval == 0 && !user->owner) + guac_client_owner_notify_join(client, user); + return retval; } @@ -335,12 +335,12 @@ void guac_client_remove_user(guac_client* client, guac_user* user) { if (user->owner) client->__owner = NULL; - /* Update owner of user having left the connection. */ - else - guac_client_owner_notify_leave(client, user); - pthread_rwlock_unlock(&(client->__users_lock)); + /* Update owner of user having left the connection. */ + if (!user->owner) + guac_client_owner_notify_leave(client, user); + /* Call handler, if defined */ if (user->leave_handler) user->leave_handler(user);