Mercurial > hg > octave-nkf > gnulib-hg
changeset 1400:8e5de8bcae9f
(read_filesystem_list) [MOUNTED_GETMNTENT2]:
Always close stream and file descriptor before returning.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Tue, 30 Jun 1998 03:56:57 +0000 |
parents | edb0581923b9 |
children | 494c9b824a23 |
files | lib/mountlist.c |
diffstat | 1 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -532,6 +532,7 @@ FILE *fp; int ret; int lockfd = -1; + int fail = 0; # if defined F_RDLCK && defined F_SETLKW /* MNTTAB_LOCK is a macro name of our own invention; it's not present in @@ -557,7 +558,12 @@ fp = fopen (table, "r"); if (fp == NULL) - return NULL; + { + /* FIXME maybe: this close could clobber errno from fopen failure. */ + if (0 <= lockfd) + close (lockfd); + return NULL; + } while ((ret = getmntent (fp, &mnt)) == 0) { @@ -578,10 +584,13 @@ } if (ret > 0) - return NULL; + fail = 1; if (fclose (fp) == EOF) - return NULL; + fail = 1; if (0 <= lockfd && close (lockfd) != 0) + fail = 1; + + if (fail) return NULL; } #endif /* MOUNTED_GETMNTENT2. */