From: John Olheiser Date: Thu, 21 Jul 2022 07:25:52 +0000 (-0500) Subject: Explicit mutext (un)locking (#462) X-Git-Tag: v1.7.2~112 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=217e78eebd5b878d4e1c96630cf417d8de40368b;p=fsnotify.git Explicit mutext (un)locking (#462) Signed-off-by: jolheiser --- 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()