From 5f03d2ac51649c98c8ba6bb8235cbe9917ccd6d2 Mon Sep 17 00:00:00 2001 From: pilot Date: Wed, 16 Aug 2023 09:57:26 +0000 Subject: [PATCH] close fd when error --- epoll.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/epoll.go b/epoll.go index 3598f5b..6a56bcf 100644 --- a/epoll.go +++ b/epoll.go @@ -41,18 +41,25 @@ type epoll struct { } func newEpoll() (*epoll, error) { - fd, err := syscall.EpollCreate1(syscall.EPOLL_CLOEXEC) + fd, err := syscall.EpollCreate1(0) if err != nil { return nil, err } - signalFds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_SEQPACKET|syscall.SOCK_CLOEXEC, 0) + signalFds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_SEQPACKET, 0) if err != nil { + syscall.Close(fd) return nil, err } - err = syscall.EpollCtl(fd, syscall.EPOLL_CTL_ADD, signalFds[0], &syscall.EpollEvent{Events: syscall.EPOLLIN, Fd: int32(signalFds[0])}) + err = syscall.EpollCtl(fd, syscall.EPOLL_CTL_ADD, signalFds[0], &syscall.EpollEvent{ + Events: syscall.EPOLLIN, + Fd: int32(signalFds[0]), + }) if err != nil { + syscall.Close(fd) + syscall.Close(signalFds[0]) + syscall.Close(signalFds[1]) return nil, err }