vhdlpp: Fixed a few memory leaks.

This commit is contained in:
Maciej Suminski 2015-06-11 17:16:16 +02:00
parent b3c1fa3e85
commit b666b9c0bf
5 changed files with 62 additions and 11 deletions

View File

@ -129,12 +129,21 @@ ExpAggregate::ExpAggregate(std::list<element_t*>*el)
elements_[idx++] = el->front();
el->pop_front();
}
delete el;
}
ExpAggregate::~ExpAggregate()
{
for (size_t idx = 0 ; idx < elements_.size() ; idx += 1)
delete elements_[idx];
for(std::vector<element_t*>::iterator it = elements_.begin();
it != elements_.end(); ++it) {
delete *it;
}
for(std::vector<choice_element>::iterator it = aggregate_.begin();
it != aggregate_.end(); ++it) {
delete it->choice;
delete it->expr;
}
}
Expression* ExpAggregate::clone() const
@ -539,6 +548,7 @@ ExpName::ExpName(ExpName*prefix, perm_string nn, Expression*msb, Expression*lsb)
ExpName::~ExpName()
{
delete index_;
delete lsb_;
}
bool ExpName::symbolic_compare(const Expression*that) const

View File

@ -678,6 +678,11 @@ class ExpName : public Expression {
public:
index_t(Expression*idx, Expression*size, Expression*offset = NULL) :
idx_(idx), size_(size), offset_(offset) {}
~index_t() {
delete idx_;
delete size_;
delete offset_;
}
int emit(ostream&out, Entity*ent, ScopeBase*scope);

View File

@ -673,6 +673,11 @@ int ExpName::emit(ostream&out, Entity*ent, ScopeBase*scope)
if(try_workarounds_(out, ent, scope, indices, field_size)) {
emit_workaround_(out, ent, scope, indices, field_size);
for(list<index_t*>::iterator it = indices.begin();
it != indices.end(); ++it)
{
delete *it;
}
return 0;
}
@ -753,7 +758,7 @@ bool ExpName::check_const_array_workaround_(const VTypeArray*arr,
data_size = element->get_width(scope);
if(data_size < 0)
return false;
indices.push_back(new index_t(index_, new ExpInteger(data_size)));
indices.push_back(new index_t(index_->clone(), new ExpInteger(data_size)));
return true;
}

View File

@ -830,11 +830,17 @@ else_when_waveform
concurrent_signal_assignment_statement /* IEEE 1076-2008 P11.6 */
: concurrent_simple_signal_assignment
| IDENTIFIER ':' concurrent_simple_signal_assignment { $$ = $3; }
| IDENTIFIER ':' concurrent_simple_signal_assignment
{ delete[] $1;
$$ = $3;
}
| concurrent_conditional_signal_assignment
| IDENTIFIER ':' concurrent_conditional_signal_assignment { $$ = $3; }
| IDENTIFIER ':' concurrent_conditional_signal_assignment
{ delete[] $1;
$$ = $3;
}
| selected_signal_assignment
@ -975,6 +981,7 @@ direction : K_to { $$ = false; } | K_downto { $$ = true; } ;
element_association
: choices ARROW expression
{ ExpAggregate::element_t*tmp = new ExpAggregate::element_t($1, $3);
delete $1;
$$ = tmp;
}
| expression
@ -998,7 +1005,9 @@ element_association_list
element_declaration
: identifier_list ':' subtype_indication ';'
{ $$ = record_elements($1, $3); }
{ $$ = record_elements($1, $3);
delete $1;
}
;
element_declaration_list
@ -1313,7 +1322,7 @@ identifier_list
}
;
identifier_opt : IDENTIFIER { $$ = $1; } | { $$ = 0; } ;
identifier_opt : IDENTIFIER { $$ = $1; } | { $$ = 0; } ;
identifier_colon_opt : IDENTIFIER ':' { $$ = $1; } | { $$ = 0; };
@ -1879,6 +1888,7 @@ primary
VHDL syntax). */
| IDENTIFIER '(' association_list ')'
{ sorrymsg(@1, "Function calls not supported\n");
delete[] $1;
$$ = 0;
}
@ -1901,12 +1911,14 @@ procedure_call
{
ProcedureCall* tmp = new ProcedureCall(lex_strings.make($1));
sorrymsg(@1, "Procedure calls are not supported.\n");
delete[] $1;
$$ = tmp;
}
| IDENTIFIER '(' association_list ')'
{
ProcedureCall* tmp = new ProcedureCall(lex_strings.make($1), $3);
sorrymsg(@1, "Procedure calls are not supported.\n");
delete[] $1;
$$ = tmp;
}
| IDENTIFIER '(' error ')'
@ -1918,7 +1930,10 @@ procedure_call
;
procedure_call_statement
: IDENTIFIER ':' procedure_call { $$ = $3; }
: IDENTIFIER ':' procedure_call
{ delete[] $1;
$$ = $3;
}
| procedure_call { $$ = $1; }
;
@ -2272,6 +2287,7 @@ severity
errormsg(@1, "Invalid severity level (possible values: NOTE, WARNING, ERROR, FAILURE).\n");
$$ = ReportStmt::UNSPECIFIED;
}
delete[] $2;
}
severity_opt
@ -2407,7 +2423,10 @@ signal_assignment
signal_assignment_statement
: signal_assignment
| IDENTIFIER ':' signal_assignment { $$ = $3; }
| IDENTIFIER ':' signal_assignment
{ delete[] $1;
$$ = $3;
}
subprogram_body_start
: subprogram_specification K_is
@ -2496,6 +2515,7 @@ subprogram_statement_part
subtype_declaration
: K_subtype IDENTIFIER K_is subtype_indication ';'
{ perm_string name = lex_strings.make($2);
delete[] $2;
if ($4 == 0) {
errormsg(@1, "Failed to declare type name %s.\n", name.str());
} else {
@ -2645,7 +2665,10 @@ use_clauses_opt
variable_assignment_statement /* IEEE 1076-2008 P10.6.1 */
: variable_assignment
| IDENTIFIER ':' variable_assignment { $$ = $3; }
| IDENTIFIER ':' variable_assignment
{ delete[] $1;
$$ = $3;
}
variable_assignment
: name VASSIGN expression ';'

View File

@ -82,7 +82,15 @@ SubprogramHeader::SubprogramHeader(perm_string nam, list<InterfacePort*>*ports,
SubprogramHeader::~SubprogramHeader()
{
delete body_;
delete ports_;
if(ports_) {
for(list<InterfacePort*>::iterator it = ports_->begin();
it != ports_->end(); ++it)
{
delete *it;
}
delete ports_;
}
}
bool SubprogramHeader::compare_specification(SubprogramHeader*that) const