From 397b56dc9de331adb5694c6c60b26edd8ba414e6 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Mon, 5 Jun 2017 12:43:37 -0700 Subject: [PATCH] Use defer when expected --- writer.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/writer.go b/writer.go index 75c1b50..a58d717 100644 --- a/writer.go +++ b/writer.go @@ -41,17 +41,15 @@ func SyncWriter(w io.Writer) io.Writer { // Write implements the io.Writer interface. func (s *syncWriter) Write(p []byte) (n int, err error) { s.mu.Lock() - n, err = s.lw.Write(p) - s.mu.Unlock() - return + defer s.mu.Unlock() + return s.lw.Write(p) } // WriteLevel implements the LevelWriter interface. func (s *syncWriter) WriteLevel(l Level, p []byte) (n int, err error) { s.mu.Lock() - n, err = s.lw.WriteLevel(l, p) - s.mu.Unlock() - return + defer s.mu.Unlock() + return s.lw.WriteLevel(l, p) } type multiLevelWriter struct {