Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix big memory leak on client disconnect #574

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts here:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I am unsure this is more clear. But I think it will work. However it would be best to test first (as the other code was tested). For me it is at the moment not so easy to test,
  2. Sadly I have no knowledge of windows threads. A similar fix might be needed. The pull request however only fixes the pthread memory leak.

#endif

return THREAD_ROUTINE_RETURN_VALUE;
}
Expand Down Expand Up @@ -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.
Expand Down