diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-02-14 07:11:38 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-02-14 07:11:38 +0100 |
commit | 781bd247805ff75f568d0224190580a762f44074 (patch) | |
tree | 3be5dbe6885a9adbed049f3dbfe7c5b1403ca6be /zyklonb.c | |
parent | c1d251840761fc8d8be25216394dfa3cc299c7cb (diff) | |
download | xK-781bd247805ff75f568d0224190580a762f44074.tar.gz xK-781bd247805ff75f568d0224190580a762f44074.tar.xz xK-781bd247805ff75f568d0224190580a762f44074.zip |
Fix resource leaks in socks_connect()
Diffstat (limited to 'zyklonb.c')
-rw-r--r-- | zyklonb.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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 ----------------------------------------------------------------- |