From aadb0c175e46458afa43bfad3b495419a4df5a2a Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Sat, 11 Oct 2025 15:17:08 -0700 Subject: [PATCH] Fix memory leaks found by paranoia_parallel examples. In function inp_probe the changes were sufficient for probe-i-dev.cir, but this function has complex control flow in its large for loop. So, I did not want to break it, and thought it better to confine the fixes to this one test circuit. Probably inp_probe needs to be refactored by someone who knows its ins and outs. In function ENHtranslate_poly the linesource field should be set to string literal "internal" to be consistent with insert_new_line(...) usage for internal cards. --- src/frontend/inpc_probe.c | 14 +++++++++++++- src/xspice/enh/enhtrans.c | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/frontend/inpc_probe.c b/src/frontend/inpc_probe.c index 99c4bcc5d..600ee1913 100644 --- a/src/frontend/inpc_probe.c +++ b/src/frontend/inpc_probe.c @@ -48,6 +48,7 @@ void inp_probe(struct card* deck) int skip_control = 0; int skip_subckt = 0; wordlist* probes = NULL, *probeparams = NULL, *wltmp, *allsaves = NULL; + wordlist *next_wl = NULL; bool haveall = FALSE, havedifferential = FALSE, t = TRUE, havesave = FALSE; NGHASHPTR instances; /* instance hash table */ int ee = 0; /* serial number for sources */ @@ -140,7 +141,12 @@ void inp_probe(struct card* deck) } } /* don't free the wl_word, they belong to the cards */ - tfree(probes); + wltmp = probes; + while (wltmp) { + next_wl = wltmp->wl_next; + tfree(wltmp); // Do not free the wl_word + wltmp = next_wl; + } /* Set up the hash table for all instances (instance name is key, data is the storage location of the card) */ @@ -188,6 +194,7 @@ void inp_probe(struct card* deck) if (!instname) continue; nghash_insert(instances, instname, card); + tfree(instname); } if (haveall || probeparams == NULL) { @@ -882,6 +889,7 @@ void inp_probe(struct card* deck) tmpcard = nghash_find(instances, instname); if (!tmpcard) { fprintf(stderr, "Warning: Could not find the instance line for %s,\n .probe %s will be ignored\n", instname, wltmp->wl_word); + tfree(instname); continue; } char* thisline = tmpcard->line; @@ -917,6 +925,7 @@ void inp_probe(struct card* deck) else if (err == 3) { fprintf(stderr, "Warning: Number of nodes mismatch,\n .probe %s will be ignored\n", wltmp->wl_word); } + tfree(instname); continue; } else if (!haveall) { @@ -934,6 +943,9 @@ void inp_probe(struct card* deck) } } + if (probeparams) { + wl_free(probeparams); + } nghash_free(instances, NULL, NULL); } diff --git a/src/xspice/enh/enhtrans.c b/src/xspice/enh/enhtrans.c index 2eb23aa2a..649724748 100644 --- a/src/xspice/enh/enhtrans.c +++ b/src/xspice/enh/enhtrans.c @@ -124,8 +124,8 @@ ENHtranslate_poly( l1->linenum = d->linenum; l2->linenum = d->linenum; - l1->linesource = copy("internal"); - l2->linesource = copy("internal"); + l1->linesource = "internal"; + l2->linesource = "internal"; /* Create the translated cards */ d->error = two2three_translate(d->line, &(l1->line), &(l2->line));