From 5c28b9e987fec20433a168bc565589e7be640889 Mon Sep 17 00:00:00 2001 From: nhmall Date: Wed, 13 Nov 2024 09:07:10 -0500 Subject: [PATCH] fix another memory leak In sys_early_init(), the values for sysopt.gdbpath and sysopt.greppath were being assigned by calling dupstr() without ensuring that a value previously assigned by dupstr() were free()'d. Also, the sysopt struct definition is changed to sysopt_s, not because there's anything wrong with the original struct sysopt sysopt; but because I couldn't convince the debugger to use the correct thing when trying to track down the leak. --- include/sys.h | 4 ++-- src/sys.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/sys.h b/include/sys.h index 764d7435f..63f7f5394 100644 --- a/include/sys.h +++ b/include/sys.h @@ -5,7 +5,7 @@ #ifndef SYS_H #define SYS_H -struct sysopt { +struct sysopt_s { char *support; /* local support contact */ char *recover; /* how to run recover - may be overridden by win port */ char *wizards; /* space-separated list of usernames */ @@ -60,7 +60,7 @@ struct sysopt { * 1: suppress it */ }; -extern struct sysopt sysopt; +extern struct sysopt_s sysopt; #define SYSOPT_SEDUCE sysopt.seduce diff --git a/src/sys.c b/src/sys.c index 2cef92a87..6c2ee1b51 100644 --- a/src/sys.c +++ b/src/sys.c @@ -15,7 +15,7 @@ at runtime by setting up a value for "DEBUGFILES" in the environment */ #endif -struct sysopt sysopt; +struct sysopt_s sysopt; void sys_early_init(void) @@ -66,7 +66,11 @@ sys_early_init(void) #ifdef PANICTRACE /* panic options */ + if (sysopt.gdbpath) + free((genericptr_t) sysopt.gdbpath), sysopt.gdbpath = 0; sysopt.gdbpath = dupstr(GDBPATH); + if (sysopt.greppath) + free((genericptr_t) sysopt.greppath), sysopt.greppath = 0; sysopt.greppath = dupstr(GREPPATH); #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) sysopt.panictrace_gdb = 1;