When the client code closes the connection to the server it doesn't close the socket. Therefore VNC clients that don't exit immediately after closing the connection to the server are leaking file handles. F.ex. VNC connections via SSH tunnel keep the ssh connection open, because the socket isn't closed.
KDE's krdc is one example for a client that suffers from this problem. See my original bug report here
<https://bugs.kde.org/show_bug.cgi?id=184840>
The attached patch fixes the problem.
Add close() to rfbClientCleanup()
Slightly improved patch: check for non-negative file descriptor, not non-zero one.
Thanks, I applied your patch (with an indentation fix)