Commit 9ed41066 authored by Christian Beier's avatar Christian Beier Committed by Johannes Schindelin

Fix checks for socket values, 0 is a legal value.

To make this work, we also have to initialize sockets
to a default value of -1.

Also close a client listen socket if it's open.
Signed-off-by: 's avatarChristian Beier <dontmind@freeshell.org>
Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent d4c43c1b
...@@ -127,7 +127,7 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout) ...@@ -127,7 +127,7 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)
client->listenSpecified = TRUE; client->listenSpecified = TRUE;
if (! client->listenSock) if (client->listenSock < 0)
{ {
client->listenSock = ListenAtTcpPort(client->listenPort); client->listenSock = ListenAtTcpPort(client->listenPort);
......
...@@ -388,7 +388,7 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) ...@@ -388,7 +388,7 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
fclose(rec->file); fclose(rec->file);
return FALSE; return FALSE;
} }
client->sock = 0; client->sock = -1;
return TRUE; return TRUE;
} }
......
...@@ -190,7 +190,8 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel, ...@@ -190,7 +190,8 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
#ifdef LIBVNCSERVER_WITH_CLIENT_TLS #ifdef LIBVNCSERVER_WITH_CLIENT_TLS
client->tlsSession = NULL; client->tlsSession = NULL;
#endif #endif
client->sock = -1;
client->listenSock = -1;
return client; return client;
} }
...@@ -334,8 +335,10 @@ void rfbClientCleanup(rfbClient* client) { ...@@ -334,8 +335,10 @@ void rfbClientCleanup(rfbClient* client) {
#endif #endif
FreeTLS(client); FreeTLS(client);
if (client->sock > 0) if (client->sock >= 0)
close(client->sock); close(client->sock);
if (client->listenSock >= 0)
close(client->listenSock);
free(client->desktopName); free(client->desktopName);
free(client->serverHost); free(client->serverHost);
free(client); free(client);
......
...@@ -485,7 +485,7 @@ rfbClientConnectionGone(rfbClientPtr cl) ...@@ -485,7 +485,7 @@ rfbClientConnectionGone(rfbClientPtr cl)
if (cl->next) if (cl->next)
cl->next->prev = cl->prev; cl->next->prev = cl->prev;
if(cl->sock>0) if(cl->sock>=0)
close(cl->sock); close(cl->sock);
if (cl->scaledScreen!=NULL) if (cl->scaledScreen!=NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment