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.DU : 二重アンロック

要旨

ミューテックスが、間にロックされないまま2回 pthread_mutex_unlock() でアンロックされようとしています。

より広範囲な二重アンロックをチェックする場合は ロック取得の欠如 を有効にしてください。

プロパティ

クラス名 Double Unlock
日本語クラス名 二重アンロック
クラス分類 信頼性 (reliability)
ニーモニック CONCURRENCY.DU
カテゴリー
MisraC2025 MisraC2025:D.4.1 Run-time failures shall be minimized
MisraC2023 MisraC2023:D.4.1 Run-time failures shall be minimized
Misra2012 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:765 Multiple Unlocks of a Critical Resource
  CWE:832 Unlock of a Resource that is not Locked
CERT-C CERT-C:POS48-C Do not unlock or destroy another POSIX thread's mutex
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Double Unlock"

ワーニングを引き起こす関数

A warning is triggered if a lock release function is called to acquire a mutex that is not currently locked: either it has never been locked or it has previously been unlocked without an intervening lock.

For the purpose of this check:

#include <pthread.h>

void du_1(pthread_mutex_t lock){
  pthread_mutex_lock(&lock);
  pthread_mutex_unlock(&lock);
  pthread_mutex_unlock(&lock);   /* 'Double Unlock' warning issued here */
}

void du_2(pthread_mutex_t lock){
  pthread_mutex_unlock(&lock);
  pthread_mutex_lock(&lock);
  pthread_mutex_unlock(&lock);   /* 'Double Unlock' warning issued here
                                  *  - the second call to pthread_mutex_lock()
                                  *    may have failed to acquire the lock.
                                  */
}

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

注釈

既にアンロックされているミューテックスをアンロックしようとすると、デッドロックもしくは未定義動作の原因となります。

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

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