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.
This commit is contained in:
Brian Taylor 2025-10-11 15:17:08 -07:00
parent a75ecd77dc
commit aadb0c175e
2 changed files with 15 additions and 3 deletions

View File

@ -48,6 +48,7 @@ void inp_probe(struct card* deck)
int skip_control = 0; int skip_control = 0;
int skip_subckt = 0; int skip_subckt = 0;
wordlist* probes = NULL, *probeparams = NULL, *wltmp, *allsaves = NULL; wordlist* probes = NULL, *probeparams = NULL, *wltmp, *allsaves = NULL;
wordlist *next_wl = NULL;
bool haveall = FALSE, havedifferential = FALSE, t = TRUE, havesave = FALSE; bool haveall = FALSE, havedifferential = FALSE, t = TRUE, havesave = FALSE;
NGHASHPTR instances; /* instance hash table */ NGHASHPTR instances; /* instance hash table */
int ee = 0; /* serial number for sources */ 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 */ /* 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 /* Set up the hash table for all instances (instance name is key, data
is the storage location of the card) */ is the storage location of the card) */
@ -188,6 +194,7 @@ void inp_probe(struct card* deck)
if (!instname) if (!instname)
continue; continue;
nghash_insert(instances, instname, card); nghash_insert(instances, instname, card);
tfree(instname);
} }
if (haveall || probeparams == NULL) { if (haveall || probeparams == NULL) {
@ -882,6 +889,7 @@ void inp_probe(struct card* deck)
tmpcard = nghash_find(instances, instname); tmpcard = nghash_find(instances, instname);
if (!tmpcard) { if (!tmpcard) {
fprintf(stderr, "Warning: Could not find the instance line for %s,\n .probe %s will be ignored\n", instname, wltmp->wl_word); 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; continue;
} }
char* thisline = tmpcard->line; char* thisline = tmpcard->line;
@ -917,6 +925,7 @@ void inp_probe(struct card* deck)
else if (err == 3) { else if (err == 3) {
fprintf(stderr, "Warning: Number of nodes mismatch,\n .probe %s will be ignored\n", wltmp->wl_word); fprintf(stderr, "Warning: Number of nodes mismatch,\n .probe %s will be ignored\n", wltmp->wl_word);
} }
tfree(instname);
continue; continue;
} }
else if (!haveall) { else if (!haveall) {
@ -934,6 +943,9 @@ void inp_probe(struct card* deck)
} }
} }
if (probeparams) {
wl_free(probeparams);
}
nghash_free(instances, NULL, NULL); nghash_free(instances, NULL, NULL);
} }

View File

@ -124,8 +124,8 @@ ENHtranslate_poly(
l1->linenum = d->linenum; l1->linenum = d->linenum;
l2->linenum = d->linenum; l2->linenum = d->linenum;
l1->linesource = copy("internal"); l1->linesource = "internal";
l2->linesource = copy("internal"); l2->linesource = "internal";
/* Create the translated cards */ /* Create the translated cards */
d->error = two2three_translate(d->line, &(l1->line), &(l2->line)); d->error = two2three_translate(d->line, &(l1->line), &(l2->line));