From 8ff79c970a41639627a8333a5f38cab795dd414e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 5 Apr 2018 12:02:08 +0900 Subject: [PATCH] shareable: Use defer for tests --- internal/shareable/shareable.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index 953e31ce8..6062c7503 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -112,8 +112,8 @@ func (s *Image) region() (x, y, width, height int) { func (s *Image) Size() (width, height int) { backendsM.Lock() + defer backendsM.Unlock() _, _, w, h := s.region() - backendsM.Unlock() return w, h } @@ -149,15 +149,14 @@ func (s *Image) ReplacePixels(p []byte) { func (s *Image) At(x, y int) (color.Color, error) { backendsM.Lock() + defer backendsM.Unlock() ox, oy, w, h := s.region() if x < 0 || y < 0 || x >= w || y >= h { - backendsM.Unlock() return color.RGBA{}, nil } clr, err := s.backend.restorable.At(x+ox, y+oy) - backendsM.Unlock() return clr, err } @@ -207,8 +206,8 @@ func (s *Image) dispose() { func (s *Image) IsInvalidated() (bool, error) { backendsM.Lock() + defer backendsM.Unlock() v, err := s.backend.restorable.IsInvalidated() - backendsM.Unlock() return v, err }