OSDN Git Service

PR libfortran/45165
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 26 Feb 2011 15:21:45 +0000 (15:21 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 26 Feb 2011 15:21:45 +0000 (15:21 +0000)
* unix.c (fallback_access): Fix file descriptor leaks.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170517 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/io/unix.c

index dbafd0c..bc85a6c 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-26  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR libfortran/45165
+       * unix.c (fallback_access): Fix file descriptor leaks.
+
 2011-02-25  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * acinclude.m4 (LIBGFOR_CHECK_FPSETMASK): Set shell variable
index 004e860..12536ca 100644 (file)
@@ -144,11 +144,15 @@ typedef struct stat gfstat_t;
 static int
 fallback_access (const char *path, int mode)
 {
-  if ((mode & R_OK) && open (path, O_RDONLY) < 0)
+  int fd;
+
+  if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0)
     return -1;
+  close (fd);
 
-  if ((mode & W_OK) && open (path, O_WRONLY) < 0)
+  if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0)
     return -1;
+  close (fd);
 
   if (mode == F_OK)
     {