Fix logging filter over-allocation and leak.

The leak could happen in a couple cases where adding a log filter
fails: OOM and unsupported field type.
This commit is contained in:
Jon Siwek 2013-09-04 14:25:57 -05:00
parent 0678468353
commit f9dc48e573

View file

@ -538,10 +538,11 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt,
filter->fields = (threading::Field**)
realloc(filter->fields,
sizeof(threading::Field) * ++filter->num_fields);
sizeof(threading::Field*) * ++filter->num_fields);
if ( ! filter->fields )
{
--filter->num_fields;
reporter->Error("out of memory in add_filter");
return false;
}
@ -623,7 +624,10 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval)
include ? include->AsTableVal() : 0,
exclude ? exclude->AsTableVal() : 0,
"", list<int>()) )
{
delete filter;
return false;
}
// Get the path for the filter.
Val* path_val = fval->Lookup(rtype->FieldOffset("path"));