Skip to content

Commit a0e13c4

Browse files
lmbti-mo
authored andcommitted
pin: fix a bunch of fd leaks in tests
The new pin package didn't import fdtrace.TestMain until now, which is why the leaks went by unnoticed. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent f224bff commit a0e13c4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

pin/load.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pin
22

33
import (
44
"fmt"
5+
"io"
56

67
"github.com/cilium/ebpf"
78
"github.com/cilium/ebpf/internal/sys"
@@ -11,6 +12,7 @@ import (
1112
// Pinner is an interface implemented by all eBPF objects that support pinning
1213
// to a bpf virtual filesystem.
1314
type Pinner interface {
15+
io.Closer
1416
Pin(string) error
1517
}
1618

pin/load_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/cilium/ebpf"
1010
"github.com/cilium/ebpf/asm"
1111
"github.com/cilium/ebpf/internal/testutils"
12+
"github.com/cilium/ebpf/internal/testutils/fdtrace"
1213
)
1314

1415
func mustPinnedProgram(t *testing.T, path string) *ebpf.Program {
@@ -77,9 +78,15 @@ func TestLoad(t *testing.T) {
7778

7879
m, err := Load(mpath, nil)
7980
qt.Assert(t, qt.IsNil(err))
81+
defer m.Close()
8082
qt.Assert(t, qt.Satisfies(m, testutils.Contains[*ebpf.Map]))
8183

8284
p, err := Load(ppath, nil)
8385
qt.Assert(t, qt.IsNil(err))
86+
defer p.Close()
8487
qt.Assert(t, qt.Satisfies(p, testutils.Contains[*ebpf.Program]))
8588
}
89+
90+
func TestMain(m *testing.M) {
91+
fdtrace.TestMain(m)
92+
}

pin/walk_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func TestWalkDir(t *testing.T) {
2727
bpffn := func(path string, d fs.DirEntry, obj Pinner, err error) error {
2828
qt.Assert(t, qt.IsNil(err))
2929

30+
if obj != nil {
31+
defer obj.Close()
32+
}
33+
3034
if path == "." {
3135
return nil
3236
}

0 commit comments

Comments
 (0)