github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/staticcheck/testdata/src/CheckDeferLock/CheckDeferLock.go (about) 1 package pkg 2 3 import "sync" 4 5 var r sync.Mutex 6 var rw sync.RWMutex 7 8 func fn1() { 9 r.Lock() 10 defer r.Lock() // MATCH /deferring Lock right after having locked already; did you mean to defer Unlock/ 11 } 12 13 func fn2() { 14 r.Lock() 15 defer r.Unlock() 16 } 17 18 func fn3() { 19 println("") 20 defer r.Lock() 21 } 22 23 func fn4() { 24 rw.RLock() 25 defer rw.RLock() // MATCH /deferring RLock right after having locked already; did you mean to defer RUnlock/ 26 } 27 28 func fn5() { 29 rw.RLock() 30 defer rw.Lock() 31 } 32 33 func fn6() { 34 r.Lock() 35 defer rw.Lock() 36 }