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

libvncserver: Add thread protection for updateBuf #607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions include/rfb/rfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ typedef struct _rfbClientRec {
int tightPngDstDataLen;
#endif
#endif

/** for thread safety for updateBuf in rfbSendFBUpdate() */
#if defined(LIBVNCSERVER_HAVE_LIBPTHREAD) || defined(LIBVNCSERVER_HAVE_WIN32THREADS)
MUTEX(updateBufMutex);
#endif

} rfbClientRec, *rfbClientPtr;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,9 @@ rfbUpdateClient(rfbClientPtr cl)
!sraRgnEmpty(cl->requestedRegion)) {
result=TRUE;
if(screen->deferUpdateTime == 0) {
LOCK(cl->updateBufMutex);
rfbSendFramebufferUpdate(cl,cl->modifiedRegion);
UNLOCK(cl->updateBufMutex);
} else if(cl->startDeferring.tv_usec == 0) {
gettimeofday(&cl->startDeferring,NULL);
if(cl->startDeferring.tv_usec == 0)
Expand All @@ -1311,7 +1313,9 @@ rfbUpdateClient(rfbClientPtr cl)
+(tv.tv_usec-cl->startDeferring.tv_usec)/1000)
> screen->deferUpdateTime) {
cl->startDeferring.tv_usec = 0;
LOCK(cl->updateBufMutex);
rfbSendFramebufferUpdate(cl,cl->modifiedRegion);
UNLOCK(cl->updateBufMutex);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/libvncserver/rfbserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ rfbNewTCPOrUDPClient(rfbScreenInfoPtr rfbScreen,
INIT_MUTEX(cl->sendMutex);
INIT_COND(cl->deleteCond);

INIT_MUTEX(cl->updateBufMutex);

cl->state = RFB_PROTOCOL_VERSION;

cl->reverseConnection = FALSE;
Expand Down Expand Up @@ -650,6 +652,11 @@ rfbClientConnectionGone(rfbClientPtr cl)
UNLOCK(cl->sendMutex);
TINI_MUTEX(cl->sendMutex);

/* make sure updateBufMutex is unlocked before destroying */
LOCK(cl->updateBufMutex);
UNLOCK(cl->updateBufMutex);
TINI_MUTEX(cl->updateBufMutex);

#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
if (cl->screen->backgroundLoop) {
close(cl->pipe_notify_client_thread[0]);
Expand Down
Loading