From c8703b88bf72eb2e181edbe503bddb564fa4c4cc Mon Sep 17 00:00:00 2001 From: Leonardo Grasso Date: Fri, 16 Oct 2020 13:18:25 +0200 Subject: [PATCH] update(userspace/engine): handle formatters with smart pointer Co-Authored-By: Leonardo Di Donato Signed-off-by: Leonardo Grasso --- userspace/engine/formats.cpp | 10 ++++------ userspace/engine/formats.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/userspace/engine/formats.cpp b/userspace/engine/formats.cpp index ca9acf14..2de2b2a7 100644 --- a/userspace/engine/formats.cpp +++ b/userspace/engine/formats.cpp @@ -24,7 +24,7 @@ sinsp *falco_formats::s_inspector = NULL; falco_engine *falco_formats::s_engine = NULL; bool falco_formats::s_json_output = false; bool falco_formats::s_json_include_output_property = true; -sinsp_evt_formatter_cache *falco_formats::s_formatters = NULL; +std::unique_ptr falco_formats::s_formatters = NULL; const static struct luaL_reg ll_falco[] = { @@ -42,11 +42,9 @@ void falco_formats::init(sinsp *inspector, s_engine = engine; s_json_output = json_output; s_json_include_output_property = json_include_output_property; - if(!s_formatters) - { - delete(s_formatters); - } - s_formatters = new sinsp_evt_formatter_cache(s_inspector); + + // todo(leogr): we should have used std::make_unique, but we cannot since it's not C++14 + s_formatters = std::unique_ptr(new sinsp_evt_formatter_cache(s_inspector)); luaL_openlib(ls, "formats", ll_falco, 0); } diff --git a/userspace/engine/formats.h b/userspace/engine/formats.h index 32c04d95..f1302dd7 100644 --- a/userspace/engine/formats.h +++ b/userspace/engine/formats.h @@ -53,7 +53,7 @@ public: static sinsp *s_inspector; static falco_engine *s_engine; - static sinsp_evt_formatter_cache *s_formatters; + static std::unique_ptr s_formatters; static bool s_json_output; static bool s_json_include_output_property; };