Skip to content

Commit

Permalink
fix(tests): remove a possible memleak from tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Nov 16, 2023
1 parent 058aedd commit 1a4f425
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions userspace/libsinsp/test/sinsp_with_test_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,24 @@ class sinsp_with_test_input : public ::testing::Test {
return field_exists(evt, field_name, m_default_filterlist);
}

bool field_exists(sinsp_evt *evt, const std::string& field_name, filter_check_list& flist)
bool field_exists(sinsp_evt* evt, const std::string& field_name, filter_check_list& flist)
{
if (evt == nullptr) {
if(evt == nullptr)
{
throw sinsp_exception("The event class is NULL");
}

return flist.new_filter_check_from_fldname(field_name, &m_inspector, false) != nullptr;
auto new_fl = flist.new_filter_check_from_fldname(field_name, &m_inspector, false);
if(new_fl != nullptr)
{
// if can create a filter check it means that the field exists
delete new_fl;
return true;
}
else
{
return false;
}
}

// Return true if `field_name` value is not NULL for this event.
Expand Down

0 comments on commit 1a4f425

Please sign in to comment.