Stuart Henderson <[email protected]> writes: > ftp doesn't close the output file after writing it. Normally you're > exiting anyway at that point so it doesn't really matter, but if you've > specified multiple URLs on the command line this leaks 1 FD per > requested file. Most noticable if you do some lazy benchark like > "ftp -o/dev/null `yes $SOMEURL | head -1000`" and run yourself out > of FDs. > > Possible fix? > > Index: fetch.c > =================================================================== > RCS file: /cvs/src/usr.bin/ftp/fetch.c,v > retrieving revision 1.161 > diff -u -p -r1.161 fetch.c > --- fetch.c 28 Feb 2017 06:31:12 -0000 1.161 > +++ fetch.c 1 Mar 2017 23:21:46 -0000 > @@ -1041,6 +1041,8 @@ cleanup_url_get: > fclose(fin); > else if (s != -1) > close(s); > + if (out >= 0 && out != fileno(stdout)) > + close(out); > free(buf); > free(proxyhost); > free(proxyurl);
I was wondering if the "out >= 0" condition is necessary as open(2) errors are handled anyway.
