Fix #972, CON51-CPP falsely reporting that std::lock_guard requires catch#973
Merged
MichaelRFairhurst merged 1 commit intomainfrom Nov 20, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes issue #972 where the CON51-CPP query was incorrectly flagging RAII-style locks (like std::lock_guard) as requiring try-catch blocks. Since RAII-style locks automatically release on destruction, they cannot leak and should be excluded from this rule.
- Introduced a
canLeak()predicate to distinguish between leakable and non-leakable locking operations - Created
LeakableLockingOperationandNonLeakableLockingOperationabstract classes - Updated the CON51-CPP query to filter out non-leakable locks
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/common/src/codingstandards/cpp/concurrency/LockingOperation.qll | Added canLeak() predicate and two abstract classes to classify locking operations; updated MutexFunctionCall to extend LeakableLockingOperation and RAIIStyleLock to extend NonLeakableLockingOperation |
| cpp/common/src/codingstandards/cpp/concurrency/LockProtectedControlFlow.qll | Updated return type from FunctionCall to LockingOperation for better type accuracy and consistency |
| cpp/cert/src/rules/CON51-CPP/EnsureActivelyHeldLocksAreReleasedOnExceptionalConditions.ql | Added filter to exclude non-leakable locks using the new canLeak() predicate |
| cpp/cert/test/rules/CON51-CPP/test.cpp | Added test case f9 demonstrating that std::lock_guard with throwing code is compliant |
| change_notes/2025-11-19-exclude-raii-style-locks-from-con51-cpp.md | Documents the query behavior change for release notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mbaluda
approved these changes
Nov 20, 2025
Collaborator
mbaluda
left a comment
There was a problem hiding this comment.
no findings in openpilot, LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Mark certain lock operations as leakable or not, and exclude unleakable ones (RAII-style locks) from generating an alert in CON51-CPP.
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
CON51-CPPRelease change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.