# HG changeset patch # User Eric Blake # Date 1222275319 21600 # Node ID 541a421c693fb4754da54be6525d976915c677bd # Parent a4dc39a18d54b223c8588df0fe936b337b13fcf4 open, fopen: close fd leak in last patch * lib/open.c (rpl_open): Close fd before returning error. * lib/fopen.c (rpl_fopen): Close fd before returning error. * doc/posix-functions/open.texi (open): Document that Irix also has the bug. * doc/posix-functions/fopen.texi (fopen): Likewise. Reported by Paolo Bonzini. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-09-24 Eric Blake + + open, fopen: close fd leak in last patch + * lib/open.c (rpl_open): Close fd before returning error. + * lib/fopen.c (rpl_fopen): Close fd before returning error. + * doc/posix-functions/open.texi (open): Document that Irix also + has the bug. + * doc/posix-functions/fopen.texi (fopen): Likewise. + Reported by Paolo Bonzini. + 2008-09-24 Bruno Haible Ensure that a filename ending in a slash cannot be used to access a diff --git a/doc/posix-functions/fopen.texi b/doc/posix-functions/fopen.texi --- a/doc/posix-functions/fopen.texi +++ b/doc/posix-functions/fopen.texi @@ -12,7 +12,7 @@ This function does not fail when the file name argument ends in a slash and (without the slash) names a nonexistent file or a file that is not a directory, on some platforms: -HP-UX 11.00, Solaris 9. +HP-UX 11.00, Solaris 9, Irix 5.3. @item On Windows platforms (excluding Cygwin), this function does usually not recognize the @file{/dev/null} filename. diff --git a/doc/posix-functions/open.texi b/doc/posix-functions/open.texi --- a/doc/posix-functions/open.texi +++ b/doc/posix-functions/open.texi @@ -12,7 +12,7 @@ This function does not fail when the file name argument ends in a slash and (without the slash) names a nonexistent file or a file that is not a directory, on some platforms: -HP-UX 11.00, Solaris 9. +HP-UX 11.00, Solaris 9, Irix 5.3. @item On Windows platforms (excluding Cygwin), this function does usually not recognize the @file{/dev/null} filename. diff --git a/lib/fopen.c b/lib/fopen.c --- a/lib/fopen.c +++ b/lib/fopen.c @@ -72,6 +72,7 @@ if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) { + close (fd); errno = ENOTDIR; return NULL; } diff --git a/lib/open.c b/lib/open.c --- a/lib/open.c +++ b/lib/open.c @@ -115,6 +115,7 @@ if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) { + close (fd); errno = ENOTDIR; return -1; }