JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++
Binaries


CONCURRENCY.DL : Double Lock

Summary

A mutex has been locked twice, but there is no intervening unlock.

For broader checking for double-locking phenomena, enable warning classes Locked Twice and Missing Lock Release.

Properties

Class Name Double Lock
Significance reliability
Mnemonic CONCURRENCY.DL
Categories
MisraC2025 MisraC2025:22.18 Non-recursive mutexes shall not be recursively locked
  MisraC2025:D.4.1 Run-time failures shall be minimized
MisraC2023 MisraC2023:22.18 Non-recursive mutexes shall not be recursively locked
  MisraC2023:D.4.1 Run-time failures shall be minimized
Misra2012 Misra2012:22.18 Non-recursive mutexes shall not be recursively locked
  Misra2012:D.4.1 Run-time failures shall be minimized
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
CWE CWE:764 Multiple Locks of a Critical Resource
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Double Lock"

Triggering Functions

A warning is triggered if a lock acquisition function is called to acquire a mutex that has definitely already been acquired.

For the purpose of this check:

Example

#include <pthread.h>

void dl_1(pthread_mutex_t lock){
  pthread_mutex_lock(&lock);
  pthread_mutex_lock(&lock);     /* 'Double Lock' warning issued here. */
}

void dl_2(pthread_mutex_t lock){
  pthread_mutex_lock(&lock);
  pthread_mutex_unlock(&lock);
  pthread_mutex_lock(&lock);     /* 'Double Lock' warning issued here - pthread_mutex_unlock()
                                  *  may have failed to release the lock.
                                  */
}

int no_dl(pthread_mutex_t lock){
  if (!pthread_mutex_lock(&lock)){return -1;}
  if (!pthread_mutex_unlock(&lock)){return -1;}
  return pthread_mutex_lock(&lock);                /* ok: if control reaches this line,
                                                    * the call to pthread_mutex_unlock() must have succeeded
                                                    */
}

Notes

Trying to lock an already-locked mutex can cause deadlock or undefined behavior.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.