Skip to content

Commit

Permalink
GUACAMOLE-1293: Do not re-acquire __users_lock while already held for…
Browse files Browse the repository at this point in the history
… 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."
  • Loading branch information
mike-jumper committed Nov 28, 2022
1 parent 07acce8 commit e3adb97
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand All @@ -335,12 +335,12 @@ void guac_client_remove_user(guac_client* client, guac_user* user) {
if (user->owner)
client->__owner = NULL;

pthread_rwlock_unlock(&(client->__users_lock));

/* Update owner of user having left the connection. */
else
if (!user->owner)
guac_client_owner_notify_leave(client, user);

pthread_rwlock_unlock(&(client->__users_lock));

/* Call handler, if defined */
if (user->leave_handler)
user->leave_handler(user);
Expand Down

0 comments on commit e3adb97

Please sign in to comment.