Fix reference counting for lookup_ID() usages.

That function refs the ID before returning it, but callers were never
assuming responsibility for that reference.
This commit is contained in:
Jon Siwek 2014-05-01 15:00:03 -05:00
parent 5b9d190f2c
commit 8b7d5a68b2
7 changed files with 42 additions and 8 deletions

View file

@ -192,6 +192,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
string fullname = make_full_var_name(current_module.c_str(), s.c_str());
debug_msg("Function %s not defined.\n", fullname.c_str());
plr.type = plrUnknown;
Unref(id);
return;
}
@ -199,6 +200,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
{
debug_msg("Function %s not declared.\n", id->Name());
plr.type = plrUnknown;
Unref(id);
return;
}
@ -206,6 +208,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
{
debug_msg("Function %s declared but not defined.\n", id->Name());
plr.type = plrUnknown;
Unref(id);
return;
}
@ -216,9 +219,12 @@ static void parse_function_name(vector<ParseLocationRec>& result,
{
debug_msg("Function %s is a built-in function\n", id->Name());
plr.type = plrUnknown;
Unref(id);
return;
}
Unref(id);
Stmt* body = 0; // the particular body we care about; 0 = all
if ( bodies.size() == 1 )

View file

@ -39,7 +39,10 @@ FuncType* EventHandler::FType()
if ( id->Type()->Tag() != TYPE_FUNC )
return 0;
return type = id->Type()->AsFuncType();
type = id->Type()->AsFuncType();
Unref(id);
return type;
}
void EventHandler::SetLocalHandler(Func* f)

View file

@ -475,6 +475,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
type = id->Type()->Ref();
id->SetVal(new Val(this));
Unref(id);
}
BuiltinFunc::~BuiltinFunc()

View file

@ -1286,7 +1286,10 @@ static Val* get_bro_val(const char* label)
return 0;
}
return id->ID_Val();
Val* rval = id->ID_Val();
Unref(id);
return rval;
}

View file

@ -1449,6 +1449,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
}
else
{
Unref(id);
reporter->Error("identifier or enumerator value in enumerated type definition already exists");
SetError();
return;

View file

@ -385,6 +385,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
if ( arg_id && ! arg_id->IsGlobal() )
arg_id->Error("argument name used twice");
Unref(arg_id);
arg_id = install_ID(arg_i->id, module_name, false, false);
arg_id->SetType(arg_i->type->Ref());
}
@ -442,10 +443,13 @@ void end_func(Stmt* body, attr_list* attrs)
Val* internal_val(const char* name)
{
ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id )
reporter->InternalError("internal variable %s missing", name);
return id->ID_Val();
Val* rval = id->ID_Val();
Unref(id);
return rval;
}
Val* internal_const_val(const char* name)
@ -457,13 +461,17 @@ Val* internal_const_val(const char* name)
if ( ! id->IsConst() )
reporter->InternalError("internal variable %s is not constant", name);
return id->ID_Val();
Val* rval = id->ID_Val();
Unref(id);
return rval;
}
Val* opt_internal_val(const char* name)
{
ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
return id ? id->ID_Val() : 0;
Val* rval = id ? id->ID_Val() : 0;
Unref(id);
return rval;
}
double opt_internal_double(const char* name)
@ -503,6 +511,8 @@ ListVal* internal_list_val(const char* name)
return 0;
Val* v = id->ID_Val();
Unref(id);
if ( v )
{
if ( v->Type()->Tag() == TYPE_LIST )
@ -528,7 +538,9 @@ BroType* internal_type(const char* name)
if ( ! id )
reporter->InternalError("internal type %s missing", name);
return id->Type();
BroType* rval = id->Type();
Unref(id);
return rval;
}
Func* internal_func(const char* name)

View file

@ -606,22 +606,30 @@ void do_atifdef(const char* id)
{
++current_depth;
if ( ! lookup_ID(id, current_module.c_str()) )
ID* i;
if ( ! (i = lookup_ID(id, current_module.c_str())) )
{
if_stack.append(current_depth);
BEGIN(IGNORE);
}
Unref(i);
}
void do_atifndef(const char *id)
{
++current_depth;
if ( lookup_ID(id, current_module.c_str()) )
ID* i;
if ( (i = lookup_ID(id, current_module.c_str())) )
{
if_stack.append(current_depth);
BEGIN(IGNORE);
}
Unref(i);
}
void do_atelse()