Fix resource leaks in socks_connect()
This commit is contained in:
parent
c1d2518407
commit
781bd24780
27
zyklonb.c
27
zyklonb.c
@ -1018,17 +1018,11 @@ socks_connect (const char *socks_host, const char *socks_port,
|
||||
const char *host, const char *port,
|
||||
const char *username, const char *password, struct error **e)
|
||||
{
|
||||
int result = -1;
|
||||
struct addrinfo gai_hints, *gai_result;
|
||||
memset (&gai_hints, 0, sizeof gai_hints);
|
||||
gai_hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
int err = getaddrinfo (socks_host, socks_port, &gai_hints, &gai_result);
|
||||
if (err)
|
||||
{
|
||||
error_set (e, "%s: %s", "getaddrinfo", gai_strerror (err));
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long port_no;
|
||||
const struct servent *serv;
|
||||
if ((serv = getservbyname (port, "tcp")))
|
||||
@ -1036,7 +1030,14 @@ socks_connect (const char *socks_host, const char *socks_port,
|
||||
else if (!xstrtoul (&port_no, port, 10) || !port_no || port_no > UINT16_MAX)
|
||||
{
|
||||
error_set (e, "invalid port number");
|
||||
return false;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
int err = getaddrinfo (socks_host, socks_port, &gai_hints, &gai_result);
|
||||
if (err)
|
||||
{
|
||||
error_set (e, "%s: %s", "getaddrinfo", gai_strerror (err));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
struct socks_data data =
|
||||
@ -1052,14 +1053,14 @@ socks_connect (const char *socks_host, const char *socks_port,
|
||||
data.address.data.domain = host;
|
||||
}
|
||||
|
||||
int fd;
|
||||
bool success = socks_5_connect (gai_result, &data, &fd, NULL)
|
||||
|| socks_4a_connect (gai_result, &data, &fd, e);
|
||||
if (!socks_5_connect (gai_result, &data, &result, NULL))
|
||||
socks_4a_connect (gai_result, &data, &result, e);
|
||||
|
||||
freeaddrinfo (gai_result);
|
||||
if (data.bound_address.type == SOCKS_DOMAIN)
|
||||
free ((char *) data.bound_address.data.domain);
|
||||
return success ? fd : -1;
|
||||
freeaddrinfo (gai_result);
|
||||
fail:
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- Plugins -----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user