prysm-pulse/tools/analyzers/recursivelock/testdata/badlockswithstructs.go
Chase Jeter 0ea4b02b8b
Added analyzer for detecting recursive/nested mutex read locks. (#10066)
* Added analyzer for detecting recursive/nested mutex read locks.

* Added type assertion checks and removed unused 'iTypes' directory

* Clean up

* Bazel file fixes

* Cleaned up code and added comments.

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-01-14 17:12:21 +08:00

52 lines
1.4 KiB
Go

package testdata
var resource *ProtectResource = &ProtectResource{resource: "protected"}
var nested *NestedResource = &NestedResource{p: ProtectResource{resource: "hello"}}
func NestedRLockWithStructs() {
resource.RLock()
resource.GetResource() // want `found recursive read lock call`
resource.RUnlock()
}
func NestedRLockWithParam(r *ProtectResource) {
r.RLock()
r.GetResource() // want `found recursive read lock call`
r.RUnlock()
}
func NestedRLockWithMoreStructs() {
nested.p.RLock()
nested.p.GetResource() // want `found recursive read lock call`
nested.p.RUnlock()
}
func NestedRLockWithFuncLit() {
resource.RLock()
var varFuncLit func() = func() {
resource.RLock()
}
varFuncLit() // want `found recursive read lock call`
assignFuncLit := func() {
resource.RLock()
}
assignFuncLit() // want `found recursive read lock call`
obfuscateFuncLit := varFuncLit
obfuscateFuncLit() // want `found recursive read lock call`
var multiVarFuncLit1, multiVarFuncLit2 func() = func() {
resource.RLock()
}, func() {
resource.RLock()
}
multiVarFuncLit1() // want `found recursive read lock call`
multiVarFuncLit2() // want `found recursive read lock call`
multiAssignFuncLit1, multiAssignFuncLit2 := func() {
resource.RLock()
}, func() {
resource.RLock()
}
multiAssignFuncLit1() // want `found recursive read lock call`
multiAssignFuncLit2() // want `found recursive read lock call`
resource.RUnlock()
}