From 3f85fc738777b1cad36b3c944798d3f173ba1d58 Mon Sep 17 00:00:00 2001 From: bdrewery Date: Wed, 17 Sep 2014 19:09:58 +0000 Subject: If fgets(3) fails in getbounds(), show strerror(3) if not an EOF. Also fix a FILE* leak in getbounds(). Submitted by: Conrad Meyer PR: 192032 Sponsored by: EMC / Isilon Storage Division MFC after: 1 week --- sbin/savecore/savecore.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sbin/savecore') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 0f1d41e..7a5fc4c 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -151,7 +151,10 @@ getbounds(void) { } if (fgets(buf, sizeof buf, fp) == NULL) { - syslog(LOG_WARNING, "unable to read from bounds, using 0"); + if (feof(fp)) + syslog(LOG_WARNING, "bounds file is empty, using 0"); + else + syslog(LOG_WARNING, "bounds file: %s", strerror(errno)); fclose(fp); return (ret); } @@ -160,6 +163,7 @@ getbounds(void) { ret = (int)strtol(buf, NULL, 10); if (ret == 0 && (errno == EINVAL || errno == ERANGE)) syslog(LOG_WARNING, "invalid value found in bounds, using 0"); + fclose(fp); return (ret); } -- cgit v1.1