Skip to content

Commit

Permalink
Revert "libvncserver: detach client thread before ending it"
Browse files Browse the repository at this point in the history
This reverts commit 8560a5a.

It caused several crashes when ending a server: client threads would
sometimes linger around until after the server was stopped and its
rfbScreen internals free()ed, with these client threads trying to access
rfbScreen and friends: 💣.

Reopens #570
  • Loading branch information
bk138 committed Aug 30, 2023
1 parent d723655 commit 9b7b5ff
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,6 @@ clientInput(void *data)

rfbClientConnectionGone(cl);

/* We can't reliably join this thread, so detach it here
so the associated memory will be freed by the OS. */
THREAD_DETACH(cl->client_thread);

return THREAD_ROUTINE_RETURN_VALUE;
}

Expand Down Expand Up @@ -1208,7 +1204,10 @@ void rfbShutdownServer(rfbScreenInfoPtr screen,rfbBool disconnectClients) {
}

#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
if(!currentCl->screen->backgroundLoop) {
if(currentCl->screen->backgroundLoop) {
/* Wait for threads to finish. The thread has already been pipe-notified by rfbCloseClient() */
pthread_join(currentCl->client_thread, NULL);
} else {
/*
In threaded mode, rfbClientConnectionGone() is called by the client-to-server thread.
Only need to call this here for non-threaded mode.
Expand Down

0 comments on commit 9b7b5ff

Please sign in to comment.