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
The attached patch fixes the problem.