From 8560a5a72d76fc3ab3484ca41f604116807f34e8 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Sat, 5 Aug 2023 14:21:43 +0200 Subject: [PATCH] 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. --- src/libvncserver/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libvncserver/main.c b/src/libvncserver/main.c index 32519f14a..d505c52e3 100644 --- a/src/libvncserver/main.c +++ b/src/libvncserver/main.c @@ -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; } @@ -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.