From 73d68a39d3bb08030977d1656ab3f71ab012bba4 Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Fri, 20 Oct 2023 10:05:27 +0100 Subject: [PATCH] map: use t.Cleanup in createArray Signed-off-by: Lorenz Bauer --- map_test.go | 8 +------- prog_test.go | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/map_test.go b/map_test.go index 2d3e4add6..ae395320b 100644 --- a/map_test.go +++ b/map_test.go @@ -48,7 +48,6 @@ func newHash(t *testing.T) *Map { func TestMap(t *testing.T) { m := createArray(t) - defer m.Close() t.Log(m) @@ -430,7 +429,6 @@ func TestMapCloneNil(t *testing.T) { func TestMapPin(t *testing.T) { m := createArray(t) c := qt.New(t) - defer m.Close() if err := m.Put(uint32(0), uint32(42)); err != nil { t.Fatal("Can't put:", err) @@ -557,7 +555,6 @@ func TestMapPinMultiple(t *testing.T) { func TestMapPinWithEmptyPath(t *testing.T) { m := createArray(t) c := qt.New(t) - defer m.Close() err := m.Pin("") @@ -694,7 +691,6 @@ func TestMapLoadPinnedWithOptions(t *testing.T) { testutils.SkipOnOldKernel(t, "4.15", "file_flags in BPF_OBJ_GET") array := createArray(t) - defer array.Close() tmp := testutils.TempBPFFS(t) @@ -780,6 +776,7 @@ func createArray(t *testing.T) *Map { if err != nil { t.Fatal(err) } + t.Cleanup(func() { m.Close() }) return m } @@ -1276,7 +1273,6 @@ func TestIterateMapInMap(t *testing.T) { defer parent.Close() a := createArray(t) - defer a.Close() if err := parent.Put(idx, a); err != nil { t.Fatal(err) @@ -1529,7 +1525,6 @@ func TestMapName(t *testing.T) { func TestMapFromFD(t *testing.T) { m := createArray(t) - defer m.Close() if err := m.Put(uint32(0), uint32(123)); err != nil { t.Fatal(err) @@ -1597,7 +1592,6 @@ func TestMapContents(t *testing.T) { func TestMapFreeze(t *testing.T) { arr := createArray(t) - defer arr.Close() err := arr.Freeze() testutils.SkipIfNotSupported(t, err) diff --git a/prog_test.go b/prog_test.go index 78a75238c..a07d63ada 100644 --- a/prog_test.go +++ b/prog_test.go @@ -713,7 +713,6 @@ func TestProgramRejectIncorrectByteOrder(t *testing.T) { func TestProgramSpecTag(t *testing.T) { arr := createArray(t) - defer arr.Close() spec := &ProgramSpec{ Type: SocketFilter,