Browse code

pkg/filenotify: poller.Add: fix fd leaks on err

In case of errors, the file descriptor is never closed. Fix it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/08/30 05:46:46
Showing 1 changed files
... ...
@@ -54,6 +54,7 @@ func (w *filePoller) Add(name string) error {
54 54
 	}
55 55
 	fi, err := os.Stat(name)
56 56
 	if err != nil {
57
+		f.Close()
57 58
 		return err
58 59
 	}
59 60
 
... ...
@@ -61,6 +62,7 @@ func (w *filePoller) Add(name string) error {
61 61
 		w.watches = make(map[string]chan struct{})
62 62
 	}
63 63
 	if _, exists := w.watches[name]; exists {
64
+		f.Close()
64 65
 		return fmt.Errorf("watch exists")
65 66
 	}
66 67
 	chClose := make(chan struct{})