Skip to content

CON51-CPP: Falsely reports potential leaks of std::lock_guard #972

@MichaelRFairhurst

Description

@MichaelRFairhurst

Affected rules

  • 'CON51-CPP'

Description

The description of CON51-CPP recommends that users use std::lock_guard to avoid leaking locked mutexes when an exception occurs. However, it seems that this rule was likely implemented before we supported std::lock_guard in our LockProtectedControlFlowNode class, and it assumes all locks require a catch block. Most likely, we later added support for std::lock_guard and didn't update this rule to allow LockProtectedControlFlowNodes without catch blocks when the lock cannot leak.

Example

void example_function(std::mutex& m) {
  std::lock_guard<std::mutex> lg(m);

  // alert is falsely reported that this function requires a catch block to unlock lg.
  return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressStardard-CERT-C++bugSomething isn't workingfalse positive/false negativeAn issue related to observed false positives or false negatives.false-positiveAn issue representing a false positive report.support-sev1High urgency, continuous impact to customer business, no known workarounduser-reportIssue reported by an end user of CodeQL Coding Standards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      SYSTEM_READY >> ...MS