summaryrefslogtreecommitdiff
path: root/lib/mountlist.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-06-30 03:56:57 +0000
committerJim Meyering <jim@meyering.net>1998-06-30 03:56:57 +0000
commit6dda2aaa5257459d25b17b8efde2ed97d3c47d85 (patch)
tree8e6e89831152620f2e458788cc30d7b77f632e5c /lib/mountlist.c
parent3fa1d4bb24d06dc358501b63ee4ca49fd34b2647 (diff)
downloadcoreutils-6dda2aaa5257459d25b17b8efde2ed97d3c47d85.tar.xz
(read_filesystem_list) [MOUNTED_GETMNTENT2]:
Always close stream and file descriptor before returning.
Diffstat (limited to 'lib/mountlist.c')
-rw-r--r--lib/mountlist.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 94430f83c..92faf4643 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -532,6 +532,7 @@ read_filesystem_list (need_fs_type, all_fs)
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 @@ read_filesystem_list (need_fs_type, all_fs)
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 @@ read_filesystem_list (need_fs_type, all_fs)
}
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. */