From 4d519940893ff61cf8d386fca63940c205edd44f Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 1 Oct 2024 17:34:15 +0400 Subject: [PATCH] fix: add SOCK_CLOEXEC to socket creation Go runtime automatically adds this flag, but when using raw syscalls, it should be added manually. Without this flag, the process leaks a file descriptor on fork/exec. Signed-off-by: Andrey Smirnov --- ethtool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethtool.go b/ethtool.go index f309c50..77e160e 100644 --- a/ethtool.go +++ b/ethtool.go @@ -964,7 +964,7 @@ func (e *Ethtool) Close() { // NewEthtool returns a new ethtool handler func NewEthtool() (*Ethtool, error) { - fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_IP) + fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM|unix.SOCK_CLOEXEC, unix.IPPROTO_IP) if err != nil { return nil, err }