mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 18:48:20 +00:00
small fixes, less leakiness
This commit is contained in:
parent
2aa0f6da57
commit
1d39eaf32d
2 changed files with 41 additions and 58 deletions
|
@ -16,7 +16,6 @@ export {
|
||||||
name: string;
|
name: string;
|
||||||
## descriptive name. for later removal
|
## descriptive name. for later removal
|
||||||
|
|
||||||
|
|
||||||
pred: function(typ: Input::Event, left: any, right: any): bool &optional;
|
pred: function(typ: Input::Event, left: any, right: any): bool &optional;
|
||||||
## decision function, that decides if an inserton, update or removal should really be executed
|
## decision function, that decides if an inserton, update or removal should really be executed
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,8 +28,14 @@ struct InputMgr::Filter {
|
||||||
EnumVal* id;
|
EnumVal* id;
|
||||||
string name;
|
string name;
|
||||||
Func* pred;
|
Func* pred;
|
||||||
|
|
||||||
|
~Filter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InputMgr::Filter::~Filter() {
|
||||||
|
Unref(id);
|
||||||
|
}
|
||||||
|
|
||||||
struct InputMgr::ReaderInfo {
|
struct InputMgr::ReaderInfo {
|
||||||
EnumVal* id;
|
EnumVal* id;
|
||||||
EnumVal* type;
|
EnumVal* type;
|
||||||
|
@ -45,15 +51,20 @@ struct InputMgr::ReaderInfo {
|
||||||
PDict(InputHash)* lastDict;
|
PDict(InputHash)* lastDict;
|
||||||
|
|
||||||
list<string> events; // events we fire when "something" happens
|
list<string> events; // events we fire when "something" happens
|
||||||
list<InputMgr::Filter> filters; // events we fire when "something" happens
|
list<InputMgr::Filter> filters; // filters that can prevent our actions
|
||||||
|
|
||||||
// ~ReaderInfo();
|
|
||||||
|
|
||||||
|
~ReaderInfo();
|
||||||
};
|
};
|
||||||
|
|
||||||
//void InputMgr::~ReaderInfo() {
|
InputMgr::ReaderInfo::~ReaderInfo() {
|
||||||
//
|
Unref(type);
|
||||||
//}
|
Unref(tab);
|
||||||
|
Unref(itype);
|
||||||
|
Unref(rtype);
|
||||||
|
Unref(id);
|
||||||
|
|
||||||
|
delete(reader);
|
||||||
|
}
|
||||||
|
|
||||||
struct InputReaderDefinition {
|
struct InputReaderDefinition {
|
||||||
bro_int_t type; // the type
|
bro_int_t type; // the type
|
||||||
|
@ -71,10 +82,8 @@ InputReaderDefinition input_readers[] = {
|
||||||
|
|
||||||
InputMgr::InputMgr()
|
InputMgr::InputMgr()
|
||||||
{
|
{
|
||||||
//DBG_LOG(DBG_LOGGING, "this has to happen");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create a new input reader object to be used at whomevers leisure lateron.
|
// create a new input reader object to be used at whomevers leisure lateron.
|
||||||
InputReader* InputMgr::CreateReader(EnumVal* id, RecordVal* description)
|
InputReader* InputMgr::CreateReader(EnumVal* id, RecordVal* description)
|
||||||
{
|
{
|
||||||
|
@ -163,30 +172,26 @@ InputReader* InputMgr::CreateReader(EnumVal* id, RecordVal* description)
|
||||||
|
|
||||||
ReaderInfo* info = new ReaderInfo;
|
ReaderInfo* info = new ReaderInfo;
|
||||||
info->reader = reader_obj;
|
info->reader = reader_obj;
|
||||||
info->type = reader;
|
info->type = reader->Ref()->AsEnumVal();
|
||||||
Ref(reader);
|
|
||||||
info->num_idx_fields = idxfields;
|
info->num_idx_fields = idxfields;
|
||||||
info->num_val_fields = valfields;
|
info->num_val_fields = valfields;
|
||||||
info->tab = dst;
|
info->tab = dst->Ref()->AsTableVal();
|
||||||
Ref(dst);
|
info->rtype = val->Ref()->AsRecordType();
|
||||||
info->rtype = val;
|
info->id = id->Ref()->AsEnumVal();
|
||||||
Ref(val); // we save a pointer of it... I really hope that this wasn't already done anywhere.
|
info->itype = idx->Ref()->AsRecordType();
|
||||||
info->id = id;
|
|
||||||
Ref(id); // ditto...
|
|
||||||
info->itype = idx;
|
|
||||||
Ref(idx);
|
|
||||||
readers.push_back(info);
|
|
||||||
info->currDict = new PDict(InputHash);
|
info->currDict = new PDict(InputHash);
|
||||||
info->lastDict = new PDict(InputHash);
|
info->lastDict = new PDict(InputHash);
|
||||||
|
|
||||||
|
readers.push_back(info);
|
||||||
|
|
||||||
int success = reader_obj->Init(source, fieldsV.size(), idxfields, fields);
|
int success = reader_obj->Init(source, fieldsV.size(), idxfields, fields);
|
||||||
if ( success == false ) {
|
if ( success == false ) {
|
||||||
RemoveReader(id);
|
assert( RemoveReader(id) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
success = reader_obj->Update();
|
success = reader_obj->Update();
|
||||||
if ( success == false ) {
|
if ( success == false ) {
|
||||||
RemoveReader(id);
|
assert ( RemoveReader(id) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,14 +259,6 @@ bool InputMgr::RemoveReader(const EnumVal* id) {
|
||||||
|
|
||||||
i->reader->Finish();
|
i->reader->Finish();
|
||||||
|
|
||||||
|
|
||||||
Unref(i->type);
|
|
||||||
Unref(i->tab);
|
|
||||||
Unref(i->itype);
|
|
||||||
Unref(i->rtype);
|
|
||||||
Unref(i->id);
|
|
||||||
|
|
||||||
delete(i->reader);
|
|
||||||
delete(i);
|
delete(i);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -279,6 +276,8 @@ bool InputMgr::RegisterEvent(const EnumVal* id, string eventName) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove first event with name eventName
|
||||||
|
// (though there shouldn't really be several events with the same name...
|
||||||
bool InputMgr::UnregisterEvent(const EnumVal* id, string eventName) {
|
bool InputMgr::UnregisterEvent(const EnumVal* id, string eventName) {
|
||||||
ReaderInfo *i = FindReader(id);
|
ReaderInfo *i = FindReader(id);
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
|
@ -286,23 +285,18 @@ bool InputMgr::UnregisterEvent(const EnumVal* id, string eventName) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool erased = false;
|
|
||||||
|
|
||||||
std::list<string>::iterator it = i->events.begin();
|
std::list<string>::iterator it = i->events.begin();
|
||||||
while ( it != i->events.end() )
|
while ( it != i->events.end() )
|
||||||
{
|
{
|
||||||
if ( *it == eventName ) {
|
if ( *it == eventName ) {
|
||||||
it = i->events.erase(it);
|
it = i->events.erase(it);
|
||||||
return true;
|
return true;
|
||||||
// erased = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
//return erased;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,14 +329,13 @@ bool InputMgr::UnrollRecordType(vector<LogField*> *fields, const RecordType *rec
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputMgr::ForceUpdate(const EnumVal* id)
|
bool InputMgr::ForceUpdate(const EnumVal* id)
|
||||||
{
|
{
|
||||||
ReaderInfo *i = FindReader(id);
|
ReaderInfo *i = FindReader(id);
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
reporter->InternalError("Reader not found");
|
reporter->Error("Reader not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +345,7 @@ bool InputMgr::ForceUpdate(const EnumVal* id)
|
||||||
bool InputMgr::AddFilter(EnumVal *id, RecordVal* fval) {
|
bool InputMgr::AddFilter(EnumVal *id, RecordVal* fval) {
|
||||||
ReaderInfo *i = FindReader(id);
|
ReaderInfo *i = FindReader(id);
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
reporter->InternalError("Reader not found");
|
reporter->Error("Reader not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +373,7 @@ bool InputMgr::AddFilter(EnumVal *id, RecordVal* fval) {
|
||||||
bool InputMgr::RemoveFilter(EnumVal* id, const string &name) {
|
bool InputMgr::RemoveFilter(EnumVal* id, const string &name) {
|
||||||
ReaderInfo *i = FindReader(id);
|
ReaderInfo *i = FindReader(id);
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
reporter->InternalError("Reader not found");
|
reporter->Error("Reader not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +420,6 @@ Val* InputMgr::LogValToIndexVal(int num_fields, const RecordType *type, const Lo
|
||||||
assert ( position == num_fields );
|
assert ( position == num_fields );
|
||||||
|
|
||||||
return idxval;
|
return idxval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -538,7 +530,8 @@ void InputMgr::SendEntry(const InputReader* reader, const LogVal* const *vals) {
|
||||||
|
|
||||||
if ( result == false ) {
|
if ( result == false ) {
|
||||||
if ( !updated ) {
|
if ( !updated ) {
|
||||||
// throw away. Hence - we quit.
|
// throw away. Hence - we quit. And remove the entry from the current dictionary...
|
||||||
|
delete(i->currDict->RemoveEntry(idxhash));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// keep old one
|
// keep old one
|
||||||
|
@ -588,9 +581,6 @@ void InputMgr::SendEntry(const InputReader* reader, const LogVal* const *vals) {
|
||||||
|
|
||||||
++filter_iterator;
|
++filter_iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -670,13 +660,12 @@ void InputMgr::EndCurrentSend(const InputReader* reader) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//reporter->Error("Expiring element");
|
|
||||||
i->tab->Delete(ih->idxkey);
|
i->tab->Delete(ih->idxkey);
|
||||||
i->lastDict->Remove(lastDictIdxKey);
|
i->lastDict->Remove(lastDictIdxKey); // deletex in next line
|
||||||
delete(ih);
|
delete(ih);
|
||||||
}
|
}
|
||||||
|
|
||||||
i->lastDict->Clear();
|
i->lastDict->Clear(); // should be empty... but... well... who knows...
|
||||||
delete(i->lastDict);
|
delete(i->lastDict);
|
||||||
|
|
||||||
i->lastDict = i->currDict;
|
i->lastDict = i->currDict;
|
||||||
|
@ -699,11 +688,6 @@ void InputMgr::Put(const InputReader* reader, const LogVal* const *vals) {
|
||||||
} else {
|
} else {
|
||||||
RecordVal * r = new RecordVal(i->rtype);
|
RecordVal * r = new RecordVal(i->rtype);
|
||||||
|
|
||||||
/* if ( i->rtype->NumFields() != (int) i->num_val_fields ) {
|
|
||||||
reporter->InternalError("Type mismatch");
|
|
||||||
return;
|
|
||||||
} */
|
|
||||||
|
|
||||||
for ( int j = 0; j < i->rtype->NumFields(); j++) {
|
for ( int j = 0; j < i->rtype->NumFields(); j++) {
|
||||||
|
|
||||||
Val* val = 0;
|
Val* val = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue