Skip to content

Missing RUnlock on RWMutex

Description

Missing `RUnlock` on an `RWMutex` lock before returning from a function. This can cause a deadlock or other concurrency issues.

Examples

Insecure Code

go
func foo(mu *sync.RWMutex) { mu.RLock(); return }

Secure Code

go
func foo(mu *sync.RWMutex) { mu.RLock(); defer mu.RUnlock(); return }

Remediation

Add a call to `RUnlock` before returning from the function, or use a `defer` statement to ensure it is called even if an error occurs.

Rule Details

FieldValue
IDCODE-0214
CategoryConcurrency
SeverityHIGH
CWECWE-667
ConfidenceMEDIUM
ImpactMEDIUM
LikelihoodHIGH
ExploitabilityMODERATE
Tagsconcurrency, mutex
OWASPN/A

References