From b7456e988f5be288da0ccc6d31df83513d13d1c4 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 29 Dec 2014 03:40:56 -0800 Subject: [PATCH] SCP: Fix log and debug file reference count management. --- sim_console.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sim_console.c b/sim_console.c index 30aff947..327dbb88 100644 --- a/sim_console.c +++ b/sim_console.c @@ -1301,6 +1301,11 @@ char saved_debug_filename[CBUFSIZE]; if (sim_deb == NULL) /* no debug? */ return SCPE_OK; +if (sim_deb == sim_log) { /* debug is log */ + fflush (sim_deb); /* fflush is the best we can do */ + return SCPE_OK; + } + strcpy (saved_debug_filename, sim_logfile_name (sim_deb, sim_deb_ref)); sim_quiet = 1; @@ -1636,8 +1641,10 @@ t_stat sim_close_logfile (FILEREF **pref) if (NULL == *pref) return SCPE_OK; (*pref)->refcount = (*pref)->refcount - 1; -if ((*pref)->refcount > 0) +if ((*pref)->refcount > 0) { + *pref = NULL; return SCPE_OK; + } fclose ((*pref)->file); free (*pref); *pref = NULL;