diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index f9480c3a22fc..caa5ad5ef2e7 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -896,7 +896,7 @@ files_group(void *retval, void *mdata, va_list ap) break; pos = ftello(st->fp); } - if (!stayopen && st->fp != NULL) { + if (st->fp != NULL && !stayopen) { fclose(st->fp); st->fp = NULL; } diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index f729cdf1d417..7cf7f47941e3 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -921,7 +921,7 @@ files_passwd(void *retval, void *mdata, va_list ap) errnop); } while (how == nss_lt_all && !(rv & NS_TERMINATE)); fin: - if (!stayopen && st->db != NULL) { + if (st->db != NULL && !stayopen) { (void)st->db->close(st->db); st->db = NULL; }