Skip to content

Commit

Permalink
Return a unique_ptr.
Browse files Browse the repository at this point in the history
Even better, return a unique_ptr directly so callers don't have to
create their own.
  • Loading branch information
mstemm committed Dec 1, 2016
1 parent 0760b96 commit 562e872
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions userspace/engine/falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ void falco_engine::enable_rule(string &pattern, bool enabled)
m_evttype_filter.enable(pattern, enabled);
}

falco_engine::rule_result *falco_engine::process_event(sinsp_evt *ev)
unique_ptr<falco_engine::rule_result> falco_engine::process_event(sinsp_evt *ev)
{

if(should_drop_evt())
{
return NULL;
return unique_ptr<struct rule_result>();
}

if(!m_evttype_filter.run(ev))
{
return NULL;
return unique_ptr<struct rule_result>();
}

unique_ptr<struct rule_result> res(new rule_result());
Expand Down Expand Up @@ -150,7 +150,7 @@ falco_engine::rule_result *falco_engine::process_event(sinsp_evt *ev)
throw falco_exception("No function " + lua_on_event + " found in lua compiler module");
}

return res.release();
return res;
}

void falco_engine::describe_rule(string *rule)
Expand Down
2 changes: 1 addition & 1 deletion userspace/engine/falco_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class falco_engine : public falco_common
// the rule that matched. If no rule matched, returns NULL.
//
// the reutrned rule_result is allocated and must be delete()d.
rule_result *process_event(sinsp_evt *ev);
std::unique_ptr<rule_result> process_event(sinsp_evt *ev);

//
// Print details on the given rule. If rule is NULL, print
Expand Down
3 changes: 1 addition & 2 deletions userspace/falco/falco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ uint64_t do_inspect(falco_engine *engine,
// engine, which will match the event against the set
// of rules. If a match is found, pass the event to
// the outputs.
falco_engine::rule_result *res = engine->process_event(ev);
unique_ptr<falco_engine::rule_result> res = engine->process_event(ev);
if(res)
{
outputs->handle_event(res->evt, res->rule, res->priority, res->format);
delete(res);
}

num_evts++;
Expand Down

0 comments on commit 562e872

Please sign in to comment.