top: tweak that recent enhancement to startup defaults

When the new approach for startup defaults was adopted
in the reference below, a file might be left open that
technically should be closed. This situation arises in
the unlikely event the #define RCFILE_NOERR is active.

Without that #define, the program will exit early thus
rendering the open file issue moot. However, even with
that #define there was no real harm with an open file.
It simply meant a 2nd FILE struct would have been used
when, or if, the rcfile was written via a 'W' command.

Anyway, this patch ensures such a file will be closed.

Reference(s):
. Dec, 2017 - /etc/topdefaultrc introduced
commit 3e6a208ae5

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-01-05 00:00:00 -06:00 committed by Craig Small
parent e82dd07b3b
commit dfa118b4d5

View File

@ -3771,7 +3771,7 @@ error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
* line 15 : miscellaneous additional global settings * line 15 : miscellaneous additional global settings
* Any remaining lines are devoted to the 'Inspect Other' feature * Any remaining lines are devoted to the 'Inspect Other' feature
* 3. 'SYS_RCDEFAULTS' system-wide defaults if 'Rc_name' absent * 3. 'SYS_RCDEFAULTS' system-wide defaults if 'Rc_name' absent
* format is identical to #2 above */ * format is identical to #2 above */
static void configs_read (void) { static void configs_read (void) {
float tmp_delay = DEF_DELAY; float tmp_delay = DEF_DELAY;
const char *p, *p_home; const char *p, *p_home;
@ -3809,15 +3809,15 @@ static void configs_read (void) {
} }
if (fp) { if (fp) {
if ((p = config_file(fp, Rc_name, &tmp_delay))) p = config_file(fp, Rc_name, &tmp_delay);
goto default_or_error;
fclose(fp); fclose(fp);
if (p) goto default_or_error;
} else { } else {
fp = fopen(SYS_RCDEFAULTS, "r"); fp = fopen(SYS_RCDEFAULTS, "r");
if (fp) { if (fp) {
if ((p = config_file(fp, SYS_RCDEFAULTS, &tmp_delay))) p = config_file(fp, SYS_RCDEFAULTS, &tmp_delay);
goto default_or_error;
fclose(fp); fclose(fp);
if (p) goto default_or_error;
} }
} }