diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 1120d30fd2a..56828b1bee5 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2018-09-14 Kyrylo Tkachov + + * io/unix.c (fallback_access): Avoid calling close on + uninitialized file descriptor. + 2018-09-12 Kwok Cheung Yeung * runtime/minimal.c (estr_write): Define in terms of write. diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 4a133fd44bd..ad2577c44a9 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -150,13 +150,21 @@ fallback_access (const char *path, int mode) { int fd; - if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0) - return -1; - close (fd); + if (mode & R_OK) + { + if ((fd = open (path, O_RDONLY)) < 0) + return -1; + else + close (fd); + } - if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0) - return -1; - close (fd); + if (mode & W_OK) + { + if ((fd = open (path, O_WRONLY)) < 0) + return -1; + else + close (fd); + } if (mode == F_OK) {