Skip to content

Commit 8560a5a

Browse files
committed
libvncserver: detach client thread before ending it
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.
1 parent 72c24ca commit 8560a5a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/libvncserver/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ clientInput(void *data)
610610

611611
rfbClientConnectionGone(cl);
612612

613+
/* We can't reliably join this thread, so detach it here
614+
so the associated memory will be freed by the OS. */
615+
THREAD_DETACH(cl->client_thread);
616+
613617
return THREAD_ROUTINE_RETURN_VALUE;
614618
}
615619

@@ -1204,10 +1208,7 @@ void rfbShutdownServer(rfbScreenInfoPtr screen,rfbBool disconnectClients) {
12041208
}
12051209

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

0 commit comments

Comments
 (0)