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 <sgrubb@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2007-01-03 00:28:02 +01:00
parent d057115966
commit 8271f58d51
1 changed files with 2 additions and 0 deletions

View File

@ -47,6 +47,7 @@
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <setjmp.h>
#include <sys/ioctl.h>
@ -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);