From 642d51969a3fd31fb3fde1fd13dfa40e260620b7 Mon Sep 17 00:00:00 2001
From: pfg <pfg@FreeBSD.org>
Date: Sun, 15 Feb 2015 16:50:21 +0000
Subject: [PATCH] More tidy-ups on uninitialized scalar variable

As a followup to r278363, there is one more case where
stayopen can be accessed uninitialized, but even after
swapping arguments, access is possible in some other
cases so prevent it completely by initializing stayopen.

CID:	1018729
CID:	1018732
---
 lib/libc/gen/getgrent.c | 4 ++--
 lib/libc/gen/getpwent.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index caa5ad5ef2e7..43574e7dcf14 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -1303,7 +1303,7 @@ compat_group(void *retval, void *mdata, va_list ap)
 	void			*discard;
 	size_t			 bufsize, linesize;
 	off_t			 pos;
-	int			 rv, stayopen, *errnop;
+	int			 rv, stayopen = 0, *errnop;
 
 #define set_lookup_type(x, y) do { 				\
 	int i;							\
@@ -1450,7 +1450,7 @@ docompat:
 		pos = ftello(st->fp);
 	}
 fin:
-	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 7cf7f47941e3..6cd7eaf39b58 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -815,7 +815,7 @@ files_passwd(void *retval, void *mdata, va_list ap)
 	size_t			 bufsize, namesize;
 	uid_t			 uid;
 	uint32_t		 store;
-	int			 rv, stayopen, *errnop;
+	int			 rv, stayopen = 0, *errnop;
 
 	name = NULL;
 	uid = (uid_t)-1;