svn commit: r199801 - head/lib/libfetch

Attilio Rao attilio at FreeBSD.org
Wed Nov 25 14:57:07 UTC 2009


Author: attilio
Date: Wed Nov 25 14:57:07 2009
New Revision: 199801
URL: http://svn.freebsd.org/changeset/base/199801

Log:
  Fix a socket leak in ftp_request() after that a connection is established.
  
  Submitted by:	Sandvine Incorporated
  Reviewed by:	des, emaste
  Sponsored by:	Sandvine Incorporated
  MFC:		1 week

Modified:
  head/lib/libfetch/ftp.c

Modified: head/lib/libfetch/ftp.c
==============================================================================
--- head/lib/libfetch/ftp.c	Wed Nov 25 14:54:58 2009	(r199800)
+++ head/lib/libfetch/ftp.c	Wed Nov 25 14:57:07 2009	(r199801)
@@ -1122,17 +1122,19 @@ ftp_request(struct url *url, const char 
 
 	/* change directory */
 	if (ftp_cwd(conn, url->doc) == -1)
-		return (NULL);
+		goto errsock;
 
 	/* stat file */
 	if (us && ftp_stat(conn, url->doc, us) == -1
 	    && fetchLastErrCode != FETCH_PROTO
 	    && fetchLastErrCode != FETCH_UNAVAIL)
-		return (NULL);
+		goto errsock;
 
 	/* just a stat */
-	if (strcmp(op, "STAT") == 0)
+	if (strcmp(op, "STAT") == 0) {
+		ftp_disconnect(conn);
 		return (FILE *)1; /* bogus return value */
+	}
 	if (strcmp(op, "STOR") == 0 || strcmp(op, "APPE") == 0)
 		oflag = O_WRONLY;
 	else
@@ -1140,6 +1142,10 @@ ftp_request(struct url *url, const char 
 
 	/* initiate the transfer */
 	return (ftp_transfer(conn, op, url->doc, oflag, url->offset, flags));
+
+errsock:
+	ftp_disconnect(conn);
+	return (NULL);
 }
 
 /*


More information about the svn-src-all mailing list