Skip to content

Commit

Permalink
update(userspace/engine): handle formatters with smart pointer
Browse files Browse the repository at this point in the history
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
  • Loading branch information
leogr and leodido committed Oct 16, 2020
1 parent cd2e66f commit b2a2623
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions userspace/engine/formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sinsp_evt_formatter_cache> falco_formats::s_formatters = NULL;

const static struct luaL_reg ll_falco[] =
{
Expand All @@ -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<sinsp_evt_formatter_cache>(new sinsp_evt_formatter_cache(s_inspector));

luaL_openlib(ls, "formats", ll_falco, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/engine/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class falco_formats

static sinsp *s_inspector;
static falco_engine *s_engine;
static sinsp_evt_formatter_cache *s_formatters;
static std::unique_ptr<sinsp_evt_formatter_cache> s_formatters;
static bool s_json_output;
static bool s_json_include_output_property;
};

0 comments on commit b2a2623

Please sign in to comment.