From: Karel Zak Date: Tue, 2 Jan 2007 23:28:02 +0000 (+0100) Subject: more: fix file descriptor leak X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8271f58d5122e2c8a9a68653767d6ca50692040c;p=util-linux more: fix file descriptor leak When you view a file with the more command and run a shell, the file descriptor for reading the file is leaked to that process. To test, more any file. Then do !/bin/sh. At the prompt do "ls -l /proc/$$/fd" and you'll see the leaked fd. From: Steve Grubb Signed-off-by: Karel Zak --- diff --git a/text-utils/more.c b/text-utils/more.c index 2b4fceb9..72f2832a 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -478,6 +479,7 @@ checkf (fs, clearfirst) } if (magic(f, fs)) return((FILE *)NULL); + fcntl(fileno(f), F_SETFD, FD_CLOEXEC ); c = Getc(f); *clearfirst = (c == '\f'); Ungetc (c, f);