parse.y: fix several memory leaks after lookup_ID()

lookup_ID() returns a referenced pointer to the caller.  Quite a lot
of code paths don't release those references.
This commit is contained in:
Max Kellermann 2020-02-21 19:05:45 +01:00
parent e32a9a61f6
commit 80d6bbc4dc

View file

@ -688,6 +688,7 @@ expr:
{ {
id->Error("undeclared variable"); id->Error("undeclared variable");
id->SetType(error_type()); id->SetType(error_type());
Ref(id);
$$ = new NameExpr(id); $$ = new NameExpr(id);
} }
@ -701,10 +702,14 @@ expr:
$$ = new ConstExpr(t->GetVal(intval)); $$ = new ConstExpr(t->GetVal(intval));
} }
else else
{
Ref(id);
$$ = new NameExpr(id); $$ = new NameExpr(id);
}
if ( id->IsDeprecated() ) if ( id->IsDeprecated() )
reporter->Warning("%s", id->GetDeprecationWarning().c_str()); reporter->Warning("%s", id->GetDeprecationWarning().c_str());
Unref(id);
} }
} }
@ -1581,6 +1586,7 @@ event:
} }
if ( id->IsDeprecated() ) if ( id->IsDeprecated() )
reporter->Warning("%s", id->GetDeprecationWarning().c_str()); reporter->Warning("%s", id->GetDeprecationWarning().c_str());
Unref(id);
} }
$$ = new EventExpr($1, $3); $$ = new EventExpr($1, $3);
@ -1632,7 +1638,10 @@ case_type:
if ( case_var && case_var->IsGlobal() ) if ( case_var && case_var->IsGlobal() )
case_var->Error("already a global identifier"); case_var->Error("already a global identifier");
else else
{
Unref(case_var);
case_var = install_ID(name, current_module.c_str(), false, false); case_var = install_ID(name, current_module.c_str(), false, false);
}
add_local(case_var, type, INIT_NONE, 0, 0, VAR_REGULAR); add_local(case_var, type, INIT_NONE, 0, 0, VAR_REGULAR);
$$ = case_var; $$ = case_var;
@ -1656,8 +1665,11 @@ for_head:
} }
else else
{
Unref(loop_var);
loop_var = install_ID($3, current_module.c_str(), loop_var = install_ID($3, current_module.c_str(),
false, false); false, false);
}
id_list* loop_vars = new id_list; id_list* loop_vars = new id_list;
loop_vars->push_back(loop_var); loop_vars->push_back(loop_var);