Always close stream and file descriptor before returning.
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
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)
{
}
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. */