1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-09-22 04:15:55 -04:00

remove file descriptor leak when IPv6 is being used.

svn path=/trunk/net/; revision=4960
This commit is contained in:
Karl Heyes 2003-06-18 11:05:49 +00:00
parent c8d79db03a
commit 6ce5ec2b0d

View File

@ -503,32 +503,28 @@ sock_t sock_connect_wto(const char *hostname, const int port, const int timeout)
ai = head; ai = head;
while (ai) while (ai)
{ {
if ((sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol)) if ((sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol)) > -1)
> -1)
{ {
if (timeout) if (timeout)
{ {
sock_set_blocking (sock, SOCK_NONBLOCK); sock_set_blocking (sock, SOCK_NONBLOCK);
if (connect (sock, ai->ai_addr, ai->ai_addrlen) < 0) if (connect (sock, ai->ai_addr, ai->ai_addrlen) < 0)
{ {
int ret = sock_connected (sock, timeout); if (sock_connected (sock, timeout) > 0)
if (ret <= 0)
{ {
sock_close (sock); sock_set_blocking(sock, SOCK_BLOCK);
sock = SOCK_ERROR; break;
} }
} }
sock_set_blocking(sock, SOCK_BLOCK);
} }
else else
{ {
if (connect (sock, ai->ai_addr, ai->ai_addrlen) < 0) if (connect (sock, ai->ai_addr, ai->ai_addrlen) == 0)
{ break;
sock_close (sock);
sock = SOCK_ERROR;
}
} }
sock_close (sock);
} }
sock = SOCK_ERROR;
ai = ai->ai_next; ai = ai->ai_next;
} }
if (head) freeaddrinfo (head); if (head) freeaddrinfo (head);