From 217e78eebd5b878d4e1c96630cf417d8de40368b Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Thu, 21 Jul 2022 02:25:52 -0500 Subject: [PATCH] Explicit mutext (un)locking (#462) Signed-off-by: jolheiser --- windows.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/windows.go b/windows.go index 1c1fe41..ecae0ce 100644 --- a/windows.go +++ b/windows.go @@ -54,12 +54,12 @@ func NewWatcher() (*Watcher, error) { // Close removes all watches and closes the events channel. func (w *Watcher) Close() error { w.mu.Lock() - defer w.mu.Unlock() - if w.isClosed { + w.mu.Unlock() return nil } w.isClosed = true + w.mu.Unlock() // Send "quit" message to the reader goroutine ch := make(chan error) @@ -74,6 +74,7 @@ func (w *Watcher) Close() error { func (w *Watcher) Add(name string) error { w.mu.Lock() if w.isClosed { + w.mu.Unlock() return errors.New("watcher already closed") } w.mu.Unlock() -- 2.50.1