V1025. Rather than creating 'std::unique_lock' to lock on the mutex, a new variable with default value is created.

The analyzer has detected an incorrect use of the 'std::unique_lock' class potentially leading to a race condition.

Consider the following example:

class C {
  std::mutex m_mutex;
  void foo() {
    std::unique_lock <std::mutex>(m_mutex);

In this code, a new variable called 'm_mutex' is created and initialized to a default value. It means that the mutex will not be locked.

Fixed code:

void foo() {
  std::unique_lock <std::mutex> var(m_mutex);

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-820.

Bugs Found

Checked Projects
Collected Errors
12 668