From fa25edabeca1d3a7e17a73752fd592aff67e46a4 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Wed, 8 Dec 2021 00:38:19 +0100 Subject: [PATCH] fix 3 potential (small) memory leaks --- src/scheduler.c | 2 +- src/token.c | 2 +- src/xinit.c | 8 +++++++- xschem_library/xschem_simulator/simulate_ff.sch | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index fb907027..7e228868 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -2836,6 +2836,6 @@ int tclvareval(const char *script, ...) } return_code = Tcl_EvalEx(interp, str, size, TCL_EVAL_GLOBAL); va_end(args); - my_free(1381, &p); + my_free(1381, &str); return return_code; } diff --git a/src/token.c b/src/token.c index ef886028..095b981d 100644 --- a/src/token.c +++ b/src/token.c @@ -1632,7 +1632,7 @@ int print_spice_element(FILE *fd, int inst) tok_val_len = strlen(value); if(!strcmp(token, "@spiceprefix")) { - spiceprefixtag = my_malloc(301, tok_val_len+22); + my_realloc(301, &spiceprefixtag, tok_val_len+22); my_snprintf(spiceprefixtag, tok_val_len+22, "**** spice_prefix %s\n", value); value = spiceprefixtag; } diff --git a/src/xinit.c b/src/xinit.c index 3d47b202..8e43381d 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1915,7 +1915,13 @@ int Tcl_AppInit(Tcl_Interp *inter) /* source tcl file given on command line with --script */ if(tcl_script[0]) { - tclvareval("update; source {", tcl_script, "}", NULL); + char str[PATH_MAX + 40]; + /* can not use tclvareval() here because if script contains 'exit' + * program terminates before tclvareval() has a chance to cleanup + * its dynamically allocated string + */ + my_snprintf(str, S(str), "update; source {%s}", tcl_script); + Tcl_EvalEx(interp, str, -1, TCL_EVAL_GLOBAL); } if(quit) { diff --git a/xschem_library/xschem_simulator/simulate_ff.sch b/xschem_library/xschem_simulator/simulate_ff.sch index 5b893dbf..da9a3354 100644 --- a/xschem_library/xschem_simulator/simulate_ff.sch +++ b/xschem_library/xschem_simulator/simulate_ff.sch @@ -335,7 +335,7 @@ comment=" " tclcommand=" set count 0 - set duration 1000 + set duration 300 xschem select instance p8 ;# CLEAR_ xschem select instance p9 ;# CLK xschem logic_set 0 ;# reset pulse (active low)