diff --git a/userspace/libsinsp/test/sinsp_with_test_input.h b/userspace/libsinsp/test/sinsp_with_test_input.h index d69a6bf8e70..891653f770b 100644 --- a/userspace/libsinsp/test/sinsp_with_test_input.h +++ b/userspace/libsinsp/test/sinsp_with_test_input.h @@ -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.