* http.c (connect_server): Fix fd leak when connecting to a round-robin
authorDavid Shaw <dshaw@jabberwocky.com>
Tue, 1 Feb 2005 20:55:35 +0000 (20:55 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Tue, 1 Feb 2005 20:55:35 +0000 (20:55 +0000)
server set that has some down servers.  Noted by Phil Pennock.

util/ChangeLog
util/http.c

index 11fc41b..15bfbde 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-01  David Shaw  <dshaw@jabberwocky.com>
+
+       * http.c (connect_server): Fix fd leak when connecting to a
+       round-robin server set that has some down servers.  Noted by Phil
+       Pennock.
+
 2005-01-20  Werner Koch  <wk@g10code.com>
 
        * simple-gettext.c (set_gettext_file): Use MO files depending on
index 5b9a53d..989abd1 100644 (file)
@@ -859,6 +859,8 @@ connect_server( const char *server, ushort port, unsigned int flags,
              connected=1;
              break;
            }
+
+         sock_close(sock);
        }
 
       freeaddrinfo(res);
@@ -880,6 +882,8 @@ connect_server( const char *server, ushort port, unsigned int flags,
       if((host=gethostbyname(srvlist[srv].target))==NULL)
        continue;
 
+      hostfound=1;
+
       if((sock=socket(host->h_addrtype,SOCK_STREAM,0))==-1)
        {
          log_error("error creating socket: %s\n",strerror(errno));
@@ -917,6 +921,8 @@ connect_server( const char *server, ushort port, unsigned int flags,
 
       if(host->h_addr_list[i])
        break;
+
+      sock_close(sock);
     }
 #endif /* !HAVE_GETADDRINFO */
 
@@ -930,13 +936,15 @@ connect_server( const char *server, ushort port, unsigned int flags,
       else
        log_error("%s: Host not found: ec=%d\n",server,(int)WSAGetLastError());
 #else
+      int err=errno;
       if(hostfound)
-       log_error("%s: %s\n",server,strerror(errno));
+       log_error("%s: %s\n",server,strerror(err));
       else
        log_error("%s: Host not found\n",server);
 #endif
       if(sock!=-1)
        sock_close(sock);
+      errno=err;
       return -1;
     }