svn commit: r358227 - head/lib/libfetch

Kyle Evans kevans at FreeBSD.org
Fri Feb 21 18:21:58 UTC 2020


Author: kevans
Date: Fri Feb 21 18:21:57 2020
New Revision: 358227
URL: https://svnweb.freebsd.org/changeset/base/358227

Log:
  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

Modified:
  head/lib/libfetch/common.c

Modified: head/lib/libfetch/common.c
==============================================================================
--- head/lib/libfetch/common.c	Fri Feb 21 16:55:28 2020	(r358226)
+++ head/lib/libfetch/common.c	Fri Feb 21 18:21:57 2020	(r358227)
@@ -677,6 +677,7 @@ fetch_connect(const char *host, int port, int af, int 
 	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 @@ syserr:
 	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);


More information about the svn-src-all mailing list