mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
Type: RecordType::FieldDefault() returns IntrusivePtr
Fixes memory leak in EventHandler::NewEvent().
This commit is contained in:
parent
d2961c72e1
commit
d180ab0dd2
4 changed files with 6 additions and 9 deletions
|
@ -138,7 +138,7 @@ void EventHandler::NewEvent(val_list* vl)
|
|||
{
|
||||
const char* fname = args->FieldName(i);
|
||||
BroType* ftype = args->FieldType(i);
|
||||
Val* fdefault = args->FieldDefault(i);
|
||||
auto fdefault = args->FieldDefault(i);
|
||||
|
||||
auto rec = make_intrusive<RecordVal>(call_argument);
|
||||
rec->Assign(0, make_intrusive<StringVal>(fname));
|
||||
|
@ -149,10 +149,7 @@ void EventHandler::NewEvent(val_list* vl)
|
|||
rec->Assign(1, make_intrusive<StringVal>(d.Description()));
|
||||
|
||||
if ( fdefault )
|
||||
{
|
||||
Ref(fdefault);
|
||||
rec->Assign(2, fdefault);
|
||||
}
|
||||
rec->Assign(2, std::move(fdefault));
|
||||
|
||||
if ( i < vl->length() && (*vl)[i] )
|
||||
{
|
||||
|
|
|
@ -653,7 +653,7 @@ BroType* RecordType::FieldType(int field) const
|
|||
return (*types)[field]->type.get();
|
||||
}
|
||||
|
||||
Val* RecordType::FieldDefault(int field) const
|
||||
IntrusivePtr<Val> RecordType::FieldDefault(int field) const
|
||||
{
|
||||
const TypeDecl* td = FieldDecl(field);
|
||||
|
||||
|
@ -662,7 +662,7 @@ Val* RecordType::FieldDefault(int field) const
|
|||
|
||||
const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT);
|
||||
|
||||
return def_attr ? def_attr->AttrExpr()->Eval(nullptr).release() : nullptr;
|
||||
return def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr;
|
||||
}
|
||||
|
||||
int RecordType::FieldOffset(const char* field) const
|
||||
|
|
|
@ -505,7 +505,7 @@ public:
|
|||
int HasField(const char* field) const override;
|
||||
BroType* FieldType(const char* field) const override;
|
||||
BroType* FieldType(int field) const;
|
||||
Val* FieldDefault(int field) const; // Ref's the returned value; 0 if none.
|
||||
IntrusivePtr<Val> FieldDefault(int field) const;
|
||||
|
||||
// A field's offset is its position in the type_decl_list,
|
||||
// starting at 0. Returns negative if the field doesn't exist.
|
||||
|
|
|
@ -2618,7 +2618,7 @@ Val* RecordVal::LookupWithDefault(int field) const
|
|||
if ( val )
|
||||
return val->Ref();
|
||||
|
||||
return Type()->AsRecordType()->FieldDefault(field);
|
||||
return Type()->AsRecordType()->FieldDefault(field).release();
|
||||
}
|
||||
|
||||
void RecordVal::ResizeParseTimeRecords()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue