From bbcc4166282cf6dcf88a9353140eaf54d0dd841c Mon Sep 17 00:00:00 2001 From: Pieter Droogendijk Date: Sun, 8 Feb 2015 00:24:29 +0100 Subject: [PATCH] Properly clean fds when newFdPoller fails --- inotify_poller.go | 4 ++-- inotify_poller_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/inotify_poller.go b/inotify_poller.go index 581431d..0097038 100644 --- a/inotify_poller.go +++ b/inotify_poller.go @@ -19,8 +19,8 @@ type fdPoller struct { // Create a new inotify poller. // This creates an inotify handler, and an epoll handler. -func newFdPoller(fd int) (poller *fdPoller, errno error) { - poller = new(fdPoller) +func newFdPoller(fd int) (_ *fdPoller, errno error) { + poller := new(fdPoller) defer func() { if errno != nil { poller.close() diff --git a/inotify_poller_test.go b/inotify_poller_test.go index 8317658..83dc580 100644 --- a/inotify_poller_test.go +++ b/inotify_poller_test.go @@ -64,6 +64,13 @@ func makePoller(t *testing.T) (testFd, *fdPoller) { return tfd, poller } +func TestPollerWithBadFd(t *testing.T) { + _, err := newFdPoller(-1) + if err != syscall.EBADF { + t.Fatalf("Expected EBADF, got: %v", err) + } +} + func TestPollerWithData(t *testing.T) { tfd, poller := makePoller(t) defer tfd.close() -- 2.50.1