Fix memory leaks in ff/latch code.

This commit is contained in:
Brian Taylor 2022-09-16 19:34:56 -07:00 committed by Holger Vogt
parent 93bd661a3e
commit 41b7c867ff
2 changed files with 38 additions and 38 deletions

View File

@ -8313,7 +8313,6 @@ static struct card *u_instances(struct card *startcard)
int udev_ok = 0, udev_not_ok = 0;
BOOL create_called = FALSE, repeat_pass = FALSE;
BOOL skip_next = FALSE;
char *tmp = NULL, *pos, *posp, *new_str = NULL;
card = startcard;
while (card) {
@ -8336,35 +8335,36 @@ static struct card *u_instances(struct card *startcard)
}
initialize_udevice(subcktcard->line);
create_called = TRUE;
} else {
/* Pspice definition of .subckt card:
.SUBCKT <name> [node]*
+ [OPTIONAL: < <interface node> = <default value> >*]
+ [PARAMS: < <name> = <value> >* ]
+ [TEXT: < <name> = <text value> >* ]
...
.ENDS
*/
tmp = TMALLOC(char, strlen(cut_line) + 1);
(void) memcpy(tmp, cut_line, strlen(cut_line) + 1);
pos = strstr(tmp, "optional:");
posp = strstr(tmp, "params:");
/* If there is an optional: and a param: then posp > pos */
if (pos) {
/* Remove the optional: section if present */
*pos = '\0';
if (posp) {
strcat(tmp, posp);
}
}
new_str = copy(tmp);
tfree(tmp);
}
} else if (ciprefix(".ends", cut_line)) {
level--;
if (repeat_pass) {
newcard = replacement_udevice_cards();
if (newcard) {
char *tmp = NULL, *pos, *posp, *new_str = NULL, *cl;
/* Pspice definition of .subckt card:
.SUBCKT <name> [node]*
+ [OPTIONAL: < <interface node> = <default value> >*]
+ [PARAMS: < <name> = <value> >* ]
+ [TEXT: < <name> = <text value> >* ]
...
.ENDS
*/
cl = subcktcard->line;
tmp = TMALLOC(char, strlen(cl) + 1);
(void) memcpy(tmp, cl, strlen(cl) + 1);
pos = strstr(tmp, "optional:");
posp = strstr(tmp, "params:");
/* If there is an optional: and a param: then posp > pos */
if (pos) {
/* Remove the optional: section if present */
*pos = '\0';
if (posp) {
strcat(tmp, posp);
}
}
new_str = copy(tmp);
tfree(tmp);
remove_old_cards(subcktcard->nextcard, card);
subcktcard->nextcard = newcard;
tfree(subcktcard->line);

View File

@ -2766,16 +2766,16 @@ static struct dff_instance *add_dff_inout_timing_model(
arrp = dffip->d_in;
for (i = 0; i < num_gates; i++) {
if (strncmp(arrp[i], "$d_", 3) == 0) {
tfree(dffip);
delete_dff_instance(dffip);
return NULL;
}
}
if (eq(dffip->prebar, "$d_lo") || eq(dffip->prebar, "$d_nc")) {
tfree(dffip);
delete_dff_instance(dffip);
return NULL;
}
if (eq(dffip->clrbar, "$d_lo") || eq(dffip->clrbar, "$d_nc")) {
tfree(dffip);
delete_dff_instance(dffip);
return NULL;
}
@ -2841,20 +2841,20 @@ static struct dltch_instance *add_dltch_inout_timing_model(
arrp = dlp->d_in;
for (i = 0; i < num_gates; i++) {
if (strncmp(arrp[i], "$d_", 3) == 0) {
tfree(dlp);
delete_dltch_instance(dlp);
return NULL;
}
}
if (strncmp(dlp->gate, "$d_", 3) == 0) {
tfree(dlp);
delete_dltch_instance(dlp);
return NULL;
}
if (eq(dlp->prebar, "$d_lo") || eq(dlp->prebar, "$d_nc")) {
tfree(dlp);
delete_dltch_instance(dlp);
return NULL;
}
if (eq(dlp->clrbar, "$d_lo") || eq(dlp->clrbar, "$d_nc")) {
tfree(dlp);
delete_dltch_instance(dlp);
return NULL;
}
return dlp;
@ -2930,16 +2930,16 @@ static struct jkff_instance *add_jkff_inout_timing_model(
for (i = 0; i < num_gates; i++) {
if (strncmp(arrp[i], "$d_", 3) == 0 ||
strncmp(arrpk[i], "$d_", 3) == 0) {
tfree(jkffip);
delete_jkff_instance(jkffip);
return NULL;
}
}
if (eq(jkffip->prebar, "$d_lo") || eq(jkffip->prebar, "$d_nc")) {
tfree(jkffip);
delete_jkff_instance(jkffip);
return NULL;
}
if (eq(jkffip->clrbar, "$d_lo") || eq(jkffip->clrbar, "$d_nc")) {
tfree(jkffip);
delete_jkff_instance(jkffip);
return NULL;
}
return jkffip;
@ -3019,20 +3019,20 @@ static struct srff_instance *add_srff_inout_timing_model(
for (i = 0; i < num_gates; i++) {
if (strncmp(arrp[i], "$d_", 3) == 0 ||
strncmp(arrpr[i], "$d_", 3) == 0) {
tfree(srffp);
delete_srff_instance(srffp);
return NULL;
}
}
if (strncmp(srffp->gate, "$d_", 3) == 0) {
tfree(srffp);
delete_srff_instance(srffp);
return NULL;
}
if (eq(srffp->prebar, "$d_lo") || eq(srffp->prebar, "$d_nc")) {
tfree(srffp);
delete_srff_instance(srffp);
return NULL;
}
if (eq(srffp->clrbar, "$d_lo") || eq(srffp->clrbar, "$d_nc")) {
tfree(srffp);
delete_srff_instance(srffp);
return NULL;
}
return srffp;