Skip to content

Missing Mutex Unlock Before Return

Description

Missing mutex unlock before returning from a function. This could result in panics resulting from double lock operations

Examples

Insecure Code

go
func example() { mu.Lock(); return }

Secure Code

go
func example() { mu.Lock(); defer mu.Unlock(); return }

Remediation

Add a call to Unlock() on the mutex variable before returning from the function, or use a defer statement to ensure Unlock() is called when the function returns

Rule Details

FieldValue
IDCODE-0480
CategoryConcurrency
SeverityHIGH
CWECWE-667
ConfidenceMEDIUM
ImpactMEDIUM
LikelihoodHIGH
ExploitabilityEASY
Tagsmutex, lock, unlock
OWASPN/A

References