diff --git a/pkg/network/usm/sharedlibraries/ebpf_test.go b/pkg/network/usm/sharedlibraries/ebpf_test.go index 0e8436ddad0dc..418088f49acb0 100644 --- a/pkg/network/usm/sharedlibraries/ebpf_test.go +++ b/pkg/network/usm/sharedlibraries/ebpf_test.go @@ -43,16 +43,20 @@ func (s *EbpfProgramSuite) TestCanInstantiateMultipleTimes() { prog := GetEBPFProgram(cfg) require.NotNil(t, prog) - t.Cleanup(prog.Stop) + t.Cleanup(func() { + if prog != nil { + prog.Stop() + } + }) require.NoError(t, prog.InitWithLibsets(LibsetCrypto)) prog.Stop() + prog = nil prog2 := GetEBPFProgram(cfg) require.NotNil(t, prog2) - - require.NoError(t, prog.InitWithLibsets(LibsetCrypto)) t.Cleanup(prog2.Stop) + require.NoError(t, prog2.InitWithLibsets(LibsetCrypto)) } func (s *EbpfProgramSuite) TestProgramReceivesEventsWithSingleLibset() {