commit 11152e145f989bb063ad9efdf988e03396fd0b4c Author: David Goulet dgoulet@ev0ke.net Date: Mon Feb 10 22:46:06 2014 -0500
Fix: fd leak on tor resolve error
Signed-off-by: David Goulet dgoulet@ev0ke.net --- src/lib/torsocks.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c index bcf06a1..b98e0ed 100644 --- a/src/lib/torsocks.c +++ b/src/lib/torsocks.c @@ -402,25 +402,24 @@ int tsocks_tor_resolve(const char *hostname, uint32_t *ip_addr)
ret = setup_tor_connection(&conn); if (ret < 0) { - goto error; + goto end_close; }
ret = socks5_send_resolve_request(hostname, &conn); if (ret < 0) { - goto error; + goto end_close; }
/* Force IPv4 resolution for now. */ ret = socks5_recv_resolve_reply(&conn, ip_addr, sizeof(uint32_t)); if (ret < 0) { - goto error; + goto end_close; }
- ret = tsocks_libc_close(conn.fd); - if (ret < 0) { +end_close: + if (tsocks_libc_close(conn.fd) < 0) { PERROR("close"); } - end: error: return ret; @@ -451,22 +450,22 @@ int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
ret = setup_tor_connection(&conn); if (ret < 0) { - goto error; + goto end_close; }
ret = socks5_send_resolve_ptr_request(addr, &conn); if (ret < 0) { - goto error; + goto end_close; }
/* Force IPv4 resolution for now. */ ret = socks5_recv_resolve_ptr_reply(&conn, ip); if (ret < 0) { - goto error; + goto end_close; }
- ret = tsocks_libc_close(conn.fd); - if (ret < 0) { +end_close: + if (tsocks_libc_close(conn.fd) < 0) { PERROR("close"); }
tor-commits@lists.torproject.org