From 00a4e05b988ef3ad63074e9e881a4696077d9c1a Mon Sep 17 00:00:00 2001 From: Boian Bonev Date: Thu, 9 Jan 2025 22:40:29 +0200 Subject: [PATCH] Fix leak when init_params() is called with valid filter --- src/main.c | 11 +++++++++-- src/view_curses.c | 12 ------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 0222afb..5a738a2 100644 --- a/src/main.c +++ b/src/main.c @@ -53,14 +53,21 @@ You should have received a copy of the GNU General Public License along with thi static const char *progname=NULL; int maxpidlen=5; -config_t config; -params_t params; +config_t config={0}; +params_t params={0}; view_init v_init_cb=view_curses_init; view_fini v_fini_cb=view_curses_fini; view_loop v_loop_cb=view_curses_loop; inline void init_params(void) { + // initally params are zeroed; free the things possibly allocated on a second call + if (params.search_str) + free(params.search_str); + if (params.search_regx_ok) + regfree(¶ms.search_regx); + if (params.search_uc) + ucell_free(params.search_uc); memset(¶ms,0,sizeof params); params.iter=-1; params.delay=1; diff --git a/src/view_curses.c b/src/view_curses.c index f35f8fc..ec16897 100644 --- a/src/view_curses.c +++ b/src/view_curses.c @@ -2059,18 +2059,6 @@ static inline int curses_key(int ch) { case 'D': init_params(); init_config(); - // reset search regex - if (params.search_str) - free(params.search_str); - params.search_str=NULL; - if (params.search_regx_ok) { - regfree(¶ms.search_regx); - params.search_regx_ok=0; - } - if (params.search_uc) { - ucell_free(params.search_uc); - params.search_uc=NULL; - } break; case 'W': config_file_save();