Skip to content

Commit

Permalink
libvncserver: detach client thread before ending it
Browse files Browse the repository at this point in the history
Before, we were joining the thread in rfbShutdownServer(), which
cleaned up after its resources in that case, but there was no cleanup
when a client disconnected on its own, as noted in #570.

Closes #570.

Builds upon and closes #574.
  • Loading branch information
bk138 committed Aug 5, 2023
1 parent 72c24ca commit 8560a5a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ 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 @@ -1204,10 +1208,7 @@ void rfbShutdownServer(rfbScreenInfoPtr screen,rfbBool disconnectClients) {
}

#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
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 {
if(!currentCl->screen->backgroundLoop) {
/*
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 8560a5a

Please sign in to comment.