- Various minor code formatting/styling during the merge

* 'leaks' of https://github.com/MaxKellermann/zeek:
  parse.y: fix memory leak in FieldAssignExpr call
  parse.y: fix use-after-free bug in open-ended index_slice
  Type: fix use-after-free bug in init_type()
  Expr: fix memory leak in RecordCoerceExpr::Fold()
  Expr: fix memory leak in RecordCoerceExpr::InitVal()
  zeekygen/IdentifierInfo: fix memory leak in operator=()
  Func: fix memory leaks in get_func_priority()
  parse.y: fix several memory leaks after lookup_ID()
  Func: fix memory leaks in check_built_in_call()
  Var: fix memory leaks in add_global() and add_local()
  Var: add missing references to `init` in add{,_and_assign}_local()
  parse.y: hold reference on init_expr for zeekygen::Manager::Redef()
  Expr: fix two memory leaks in AssignExpr::InitVal()
  parse.y: fix memory leak after "&derepcated" without string
  RuleMatcher: delete PatternSet instances in destructor (memleak)
  option.bif: fix crash bug by referencing `Func`, not `Val`
This commit is contained in:
Jon Siwek 2020-02-24 20:41:43 -08:00
commit 4c7b1fa619
10 changed files with 98 additions and 11 deletions

View file

@ -42,6 +42,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
else if ( dt != VAR_REDEF || init || ! attr )
{
id->Error("already defined", init);
Unref(init);
return;
}
}
@ -51,6 +52,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
if ( ! id->Type() )
{
id->Error("\"redef\" used but not previously defined");
Unref(init);
return;
}
@ -64,6 +66,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
(! init || ! do_init || (! t && ! (t = init_type(init)))) )
{
id->Error("already defined", init);
Unref(init);
return;
}
@ -71,6 +74,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
if ( ! same_type(t, id->Type()) )
{
id->Error("redefinition changes type", init);
Unref(init);
return;
}
}
@ -85,6 +89,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
if ( init )
{
id->Error("double initialization", init);
Unref(init);
return;
}
@ -98,6 +103,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
if ( ! init )
{
id->Error("no type given");
Unref(init);
return;
}
@ -105,6 +111,7 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
if ( ! t )
{
id->SetType(error_type());
Unref(init);
return;
}
}
@ -185,7 +192,10 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
{
v = init_val(init, t, aggr);
if ( ! v )
{
Unref(init);
return;
}
}
if ( aggr )
@ -211,6 +221,8 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
id->SetOption();
}
Unref(init);
id->UpdateValAttrs();
if ( t && t->Tag() == TYPE_FUNC &&
@ -235,7 +247,7 @@ void add_global(ID* id, BroType* t, init_class c, Expr* init,
Stmt* add_local(ID* id, BroType* t, init_class c, Expr* init,
attr_list* attr, decl_type dt)
{
make_var(id, t, c, init, attr, dt, 0);
make_var(id, t, c, init ? init->Ref() : init, attr, dt, 0);
if ( init )
{
@ -262,7 +274,7 @@ Stmt* add_local(ID* id, BroType* t, init_class c, Expr* init,
extern Expr* add_and_assign_local(ID* id, Expr* init, Val* val)
{
make_var(id, 0, INIT_FULL, init, 0, VAR_REGULAR, 0);
make_var(id, 0, INIT_FULL, init->Ref(), 0, VAR_REGULAR, 0);
Ref(id);
return new AssignExpr(new NameExpr(id), init, 0, val);
}