Fixes memory leak in verilog attribute code.

There appears to be two leaks one with string handling, and
one with Dcl not freeing the attribute stmt list when it returns
nullptr.

Signed-off-by: Ethan Mahintorabi <ethanmoon@google.com>
This commit is contained in:
Ethan Mahintorabi 2024-04-22 21:54:12 +00:00
parent d34cde34cd
commit 7335731753
No known key found for this signature in database
GPG Key ID: 824E41B920BEA252
2 changed files with 11 additions and 3 deletions

View File

@ -505,9 +505,14 @@ attr_specs:
attr_spec: attr_spec:
ID ID
{ $$ = new sta::VerilogAttributeEntry($1, "1"); } { $$ = new sta::VerilogAttributeEntry($1, "1");
delete[] $1;
}
| ID '=' attr_spec_value | ID '=' attr_spec_value
{ $$ = new sta::VerilogAttributeEntry($1, $3); } { $$ = new sta::VerilogAttributeEntry($1, $3);
delete[] $1;
delete[] $3;
}
; ;
attr_spec_value: attr_spec_value:

View File

@ -424,8 +424,11 @@ VerilogReader::makeDcl(PortDirection *dir,
dcl_count_++; dcl_count_++;
return new VerilogDcl(dir, assign_args, attribute_stmts, line); return new VerilogDcl(dir, assign_args, attribute_stmts, line);
} }
else else {
attribute_stmts->deleteContents();
delete attribute_stmts;
return nullptr; return nullptr;
}
} }
else { else {
dcl_count_++; dcl_count_++;