From 59c14f46a296aa9ec2de5c24919d73646774feb8 Mon Sep 17 00:00:00 2001 From: Federico Aponte Date: Sat, 24 Feb 2024 16:30:22 +0100 Subject: [PATCH] refactor: shared_ptr construction Signed-off-by: Federico Aponte --- userspace/engine/evttype_index_ruleset.cpp | 3 +-- userspace/engine/evttype_index_ruleset.h | 8 +++----- userspace/engine/falco_engine.cpp | 5 ++--- userspace/falco/app/actions/init_falco_engine.cpp | 8 +++----- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/userspace/engine/evttype_index_ruleset.cpp b/userspace/engine/evttype_index_ruleset.cpp index 684afeefd5a..b3f92e84dda 100644 --- a/userspace/engine/evttype_index_ruleset.cpp +++ b/userspace/engine/evttype_index_ruleset.cpp @@ -230,8 +230,7 @@ void evttype_index_ruleset::clear() { for (size_t i = 0; i < m_rulesets.size(); i++) { - std::shared_ptr r(new ruleset_filters()); - m_rulesets[i] = r; + m_rulesets[i] = std::make_shared(); } m_filters.clear(); } diff --git a/userspace/engine/evttype_index_ruleset.h b/userspace/engine/evttype_index_ruleset.h index 7688c1bd8b9..261f42ae1f1 100644 --- a/userspace/engine/evttype_index_ruleset.h +++ b/userspace/engine/evttype_index_ruleset.h @@ -122,8 +122,8 @@ class evttype_index_ruleset: public filter_ruleset // that matched. bool run(sinsp_evt *evt, falco_rule& match); - // Evaluate an event against the ruleset and return all the - // matching rules. + // Evaluate an event against the ruleset and return all the + // matching rules. bool run(sinsp_evt *evt, std::vector& matches); libsinsp::events::set sc_codes(); @@ -164,9 +164,7 @@ class evttype_index_ruleset_factory: public filter_ruleset_factory inline std::shared_ptr new_ruleset() override { - std::shared_ptr ret( - new evttype_index_ruleset(m_filter_factory)); - return ret; + return std::make_shared(m_filter_factory); } private: diff --git a/userspace/engine/falco_engine.cpp b/userspace/engine/falco_engine.cpp index b177dbef83e..b5b9c8678ba 100644 --- a/userspace/engine/falco_engine.cpp +++ b/userspace/engine/falco_engine.cpp @@ -450,9 +450,8 @@ std::size_t falco_engine::add_source(const std::string &source, std::shared_ptr formatter_factory) { // evttype_index_ruleset is the default ruleset implementation - std::shared_ptr ruleset_factory( - new evttype_index_ruleset_factory(filter_factory)); - size_t idx = add_source(source, filter_factory, formatter_factory, ruleset_factory); + size_t idx = add_source(source, filter_factory, formatter_factory, + std::make_shared(filter_factory)); if(source == falco_common::syscall_source) { diff --git a/userspace/falco/app/actions/init_falco_engine.cpp b/userspace/falco/app/actions/init_falco_engine.cpp index 545c9ae445d..7d2bf930cb6 100644 --- a/userspace/falco/app/actions/init_falco_engine.cpp +++ b/userspace/falco/app/actions/init_falco_engine.cpp @@ -66,13 +66,11 @@ void configure_output_format(falco::app::state& s) void add_source_to_engine(falco::app::state& s, const std::string& src) { auto src_info = s.source_infos.at(src); - auto& filterchecks = *src_info->filterchecks.get(); + auto& filterchecks = *src_info->filterchecks; auto* inspector = src_info->inspector.get(); - auto filter_factory = std::shared_ptr( - new sinsp_filter_factory(inspector, filterchecks)); - auto formatter_factory = std::shared_ptr( - new sinsp_evt_formatter_factory(inspector, filterchecks)); + auto filter_factory = std::make_shared(inspector, filterchecks); + auto formatter_factory = std::make_shared(inspector, filterchecks); if(s.config->m_json_output) {