bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fopen bug on Solaris, HP-UX


From: Eric Blake
Subject: Re: fopen bug on Solaris, HP-UX
Date: Wed, 24 Sep 2008 16:56:32 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paolo Bonzini <bonzini <at> gnu.org> writes:

> 
> 
> > !   fd = open (filename, O_RDONLY);
> > !   if (fd < 0)
> >       return NULL;
> >   
> > !   if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
> > !     {
> > !       errno = ENOTDIR;
> > !       return NULL;
> > !     }
> 
> You're leaking fd here.  Same for open().

Good catch.  I'm applying this.


From: Eric Blake <address@hidden>
Date: Wed, 24 Sep 2008 10:55:19 -0600
Subject: [PATCH] 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 <address@hidden>
---
 ChangeLog                      |   10 ++++++++++
 doc/posix-functions/fopen.texi |    2 +-
 doc/posix-functions/open.texi  |    2 +-
 lib/fopen.c                    |    1 +
 lib/open.c                     |    1 +
 5 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 22bf905..49c1b2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-09-24  Eric Blake  <address@hidden>
+
+       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  <address@hidden>
 
        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
index 5fdb8da..57794fb 100644
--- a/doc/posix-functions/fopen.texi
+++ b/doc/posix-functions/fopen.texi
@@ -12,7 +12,7 @@ Portability problems fixed by Gnulib:
 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
index ed3155d..1986f0c 100644
--- a/doc/posix-functions/open.texi
+++ b/doc/posix-functions/open.texi
@@ -12,7 +12,7 @@ Portability problems fixed by Gnulib:
 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
index f64122b..d6e048b 100644
--- a/lib/fopen.c
+++ b/lib/fopen.c
@@ -72,6 +72,7 @@ rpl_fopen (const char *filename, const char *mode)
 
        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
index 317fb8a..97c30ce 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -115,6 +115,7 @@ open (const char *filename, int flags, ...)
 
          if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
            {
+             close (fd);
              errno = ENOTDIR;
              return -1;
            }
-- 
1.6.0.2







reply via email to

[Prev in Thread] Current Thread [Next in Thread]