clean up translate() deallocation

This commit is contained in:
stefan schippers 2025-01-30 23:33:51 +01:00
parent 60d180de33
commit 31a3a00c46
2 changed files with 15 additions and 8 deletions

View File

@ -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;

View File

@ -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 */