Skip to content

Commit

Permalink
close fd when error
Browse files Browse the repository at this point in the history
  • Loading branch information
pilot committed Aug 16, 2023
1 parent c7ff35d commit 5f03d2a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5f03d2a

Please sign in to comment.