fetch(3): plug some leaks

In the successful case, sockshost is not freed prior to return.

The failure case can now be hit after fetch_reopen(), which was not true
before. Thus, we need to make sure to clean up all of the conn resources
which will also close sd. For all of the points prior to fetch_reopen(), we
continue to just close sd.

CID:		1419598, 1419616
This commit is contained in:
kevans 2020-02-21 18:21:57 +00:00
parent d897ed4bf5
commit 05d081f5c9

View File

@ -677,6 +677,7 @@ fetch_connect(const char *host, int port, int af, int verbose)
if (sockshost)
if (!fetch_socks5_init(conn, host, port, verbose))
goto fail;
free(sockshost);
if (cais != NULL)
freeaddrinfo(cais);
if (sais != NULL)
@ -686,7 +687,10 @@ fetch_connect(const char *host, int port, int af, int verbose)
fetch_syserr();
fail:
free(sockshost);
if (sd >= 0)
/* Fully close if it was opened; otherwise just don't leak the fd. */
if (conn != NULL)
fetch_close(conn);
else if (sd >= 0)
close(sd);
if (cais != NULL)
freeaddrinfo(cais);