Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Mutexes are used to protect shared data structures being accessed concurrently. The thread that locks the mutex owns it, and the owning thread should be the only thread to unlock the mutex. If the mutex is destroyed while still in use, there is no more protection of critical sections and shared data are no longer protected. This rule is a specific instance of  CON31-C. Do not unlock or destroy another thread's mutex using POSIX threads.

...

In this noncompliant code example, a race condition exists between a cleanup and a worker thread. The cleanup thread destroys the lock, which it believes is no longer in use. If there is a heavy load on the system, the worker thread that held the lock can take longer than expected. If the lock is destroyed before the worker thread has completed modifying the shared data, the program may exhibit unexpected behavior.

...

sectionsectioncan

Tool

Version

Checker

Description

Fortify SCAV. 5.0 
Section
Can detect violations of this rule with CERT C Rule Pack.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...

MITRE CWE: CWE-667, "Insufficient Lockinglocking"

...

Sources

[Open Group 2004] pthread_mutex_lock()/pthread_mutex_unlock(), pthread_mutex_destroy()

...