Skip to content

Commit

Permalink
bpf: OpenMap do not leak fd
Browse files Browse the repository at this point in the history
Close fds in case of returning with an error.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Jun 19, 2023
1 parent e60ba99 commit 590a524
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/bpf/map_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,17 @@ func OpenMap(name string) (*Map, error) {

info, err := GetMapInfo(os.Getpid(), fd)
if err != nil {
unix.Close(fd)
return nil, err
}

if info.MapType == 0 {
unix.Close(fd)
return nil, fmt.Errorf("Unable to determine map type")
}

if info.KeySize == 0 {
unix.Close(fd)
return nil, fmt.Errorf("Unable to determine map key size")
}

Expand Down

0 comments on commit 590a524

Please sign in to comment.