PR-4608716.ls.c.patch   [plain text]


--- tnftpd-20091122/ls/ls.c	2009-03-01 14:58:20.000000000 -0800
+++ tnftpd/ls/ls.c	2010-01-28 14:51:45.000000000 -0800
@@ -353,15 +353,17 @@
 {
 	FTS *ftsp;
 	FTSENT *p, *chp;
-	int ch_options;
+	int ch_options, save_errno;
 
 	if ((ftsp =
 	    fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
 		err(EXIT_FAILURE, NULL);
 
 	display(NULL, fts_children(ftsp, 0));
-	if (f_listdir)
-		return;
+	if (f_listdir) {
+	    (void)fts_close(ftsp);
+	    return;
+	}
 
 	/*
 	 * If not recursing down this tree and don't need stat info, just get
@@ -403,6 +405,12 @@
 				(void)fts_set(ftsp, p, FTS_SKIP);
 			break;
 		}
+
+	/* Only care about errno set by fts_read() */
+	save_errno = errno;
+	(void)fts_close(ftsp);
+	errno = save_errno;
+	
 	if (errno)
 		err(EXIT_FAILURE, "fts_read");
 }