From 31a3a00c46c3c77c727f657409b62d4d2e77932d Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 30 Jan 2025 23:33:51 +0100 Subject: [PATCH] clean up translate() deallocation --- src/token.c | 21 ++++++++++++++------- src/xinit.c | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/token.c b/src/token.c index fbb9e305..f092bb74 100644 --- a/src/token.c +++ b/src/token.c @@ -3757,6 +3757,19 @@ const char *translate(int inst, const char* s) int sim_is_xyce; char *instname = NULL; + if(!s && inst == -1) { + if(result) my_free(_ALLOC_ID_, &result); + if(translated_tok) my_free(_ALLOC_ID_, &translated_tok); + if(get_sp_cur) { + regfree(get_sp_cur); + get_sp_cur = NULL; + } + } + + if(!s || !xctx || !xctx->inst) { + return empty; + } + if(!get_sp_cur) { get_sp_cur = my_malloc(_ALLOC_ID_, sizeof(regex_t)); /* @spice_get_current_param(...) or @spice_get_modelparam_param(...) */ @@ -3767,13 +3780,7 @@ const char *translate(int inst, const char* s) } sp_prefix = tclgetboolvar("spiceprefix"); - if(!s || !xctx || !xctx->inst) { - my_free(_ALLOC_ID_, &result); - my_free(_ALLOC_ID_, &translated_tok); - regfree(get_sp_cur); - get_sp_cur = NULL; - return empty; - } + if(inst >= xctx->instances) { dbg(0, "translate(): instance number out of bounds: %d\n", inst); return empty; diff --git a/src/xinit.c b/src/xinit.c index 46160eb2..6d3058f7 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -944,7 +944,7 @@ static void xwin_exit(void) clear_expandlabel_data(); get_sym_template(NULL, NULL); /* clear static data in function */ list_tokens(NULL, 0); /* clear static data in function */ - translate(0, NULL); /* clear static data in function */ + translate(-1, NULL); /* clear static data in function */ translate2(NULL, 0, NULL); /* clear static data in function */ translate3(NULL, 0, NULL, NULL, NULL); /* clear static data in function */ subst_token(NULL, NULL, NULL); /* clear static data in function */