diff options
author | Jim Meyering <jim@meyering.net> | 1998-06-30 14:32:53 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1998-06-30 14:32:53 +0000 |
commit | 7a314199db4c9cbcdf86929a0616d1e3f98e3bd8 (patch) | |
tree | 91ab2900960f70457f595a553959b2df12f8ffa4 | |
parent | 837a447ba4ddc5d68383fa11123969c1ea4aedd3 (diff) | |
download | coreutils-7a314199db4c9cbcdf86929a0616d1e3f98e3bd8.tar.xz |
(read_filesystem_list):
Plug file descriptor leak on failure.
Report failure if lock file can't be opened for some reason
other than nonexistence.
-rw-r--r-- | lib/mountlist.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/lib/mountlist.c b/lib/mountlist.c index 92faf4643..58ac26df4 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -532,7 +532,6 @@ 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 @@ -558,39 +557,35 @@ read_filesystem_list (need_fs_type, all_fs) fp = fopen (table, "r"); if (fp == NULL) + ret = 1; + else { - /* FIXME maybe: this close could clobber errno from fopen failure. */ - if (0 <= lockfd) - close (lockfd); - return NULL; - } - - while ((ret = getmntent (fp, &mnt)) == 0) - { - /* Don't show automounted filesystems twice on e.g., Solaris. */ - if (!all_fs && MNT_IGNORE (&mnt)) - continue; - - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); - me->me_devname = xstrdup (mnt.mnt_special); - me->me_mountdir = xstrdup (mnt.mnt_mountp); - me->me_type = xstrdup (mnt.mnt_fstype); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - me->me_next = NULL; + while ((ret = getmntent (fp, &mnt)) == 0) + { + /* Don't show automounted filesystems twice on e.g., Solaris. */ + if (!all_fs && MNT_IGNORE (&mnt)) + continue; + + me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me->me_devname = xstrdup (mnt.mnt_special); + me->me_mountdir = xstrdup (mnt.mnt_mountp); + me->me_type = xstrdup (mnt.mnt_fstype); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + me->me_next = NULL; + + /* Add to the linked list. */ + mtail->me_next = me; + mtail = me; + } - /* Add to the linked list. */ - mtail->me_next = me; - mtail = me; + if (fclose (fp) == EOF) + ret = 1; } - if (ret > 0) - fail = 1; - if (fclose (fp) == EOF) - fail = 1; if (0 <= lockfd && close (lockfd) != 0) - fail = 1; + return NULL; - if (fail) + if (ret > 0) return NULL; } #endif /* MOUNTED_GETMNTENT2. */ |