From 94a22261d939c3216c7ce7920cade555e96b5dd9 Mon Sep 17 00:00:00 2001 From: JorisHansMeijer <36713790+JorisHansMeijer@users.noreply.github.com> Date: Sat, 15 Apr 2023 13:11:34 +0200 Subject: [PATCH] Fix big memory leak on client disconnect A pthread needs to be joined or detached to prevent memory leaks --- src/libvncserver/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libvncserver/main.c b/src/libvncserver/main.c index 32519f14a..2ee90d93e 100644 --- a/src/libvncserver/main.c +++ b/src/libvncserver/main.c @@ -609,6 +609,11 @@ clientInput(void *data) cl->sock = RFB_INVALID_SOCKET; rfbClientConnectionGone(cl); + +#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD + // We can't join this thread, detach it here so the associated memory will be feed + pthread_detach(cl->client_thread); +#endif return THREAD_ROUTINE_RETURN_VALUE; } @@ -1204,10 +1209,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.