Skip to content

Commit e408f18

Browse files
committed
CPP: Fix false positives when member variable is released via capture inside lambda expression.
1 parent 6efd481 commit e408f18

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

cpp/ql/src/jsf/4.10 Classes/AV Rule 79.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ predicate freedInSameMethod(Resource r, Expr acquire) {
184184
exists(Expr releaseExpr, string kind |
185185
r.acquisitionWithRequiredKind(acquire, kind) and
186186
releaseExpr = r.getAReleaseExpr(kind) and
187-
releaseExpr.getEnclosingFunction() = acquire.getEnclosingFunction()
187+
releaseExpr.getEnclosingFunction().getEnclosingAccessHolder*() = acquire.getEnclosingFunction()
188+
// here, `getEnclosingAccessHolder*` allows us to go from a nested function or lambda
189+
// expression to the class method enclosing it.
188190
)
189191
}
190192

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/AV Rule 79.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
| DeleteThis.cpp:127:3:127:20 | ... = ... | Resource d is acquired by class MyClass9 but not released anywhere in this class. |
1212
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
1313
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
14-
| Lambda.cpp:12:3:12:21 | ... = ... | Resource r2 is acquired by class testLambda but not released anywhere in this class. |
1514
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
1615
| Lambda.cpp:26:3:26:21 | ... = ... | Resource r5 is acquired by class testLambda but not released anywhere in this class. |
1716
| Lambda.cpp:29:3:29:21 | ... = ... | Resource r6 is acquired by class testLambda but not released in the destructor. It is released from deleter_for_r6 on line 40, so this function may need to be called from the destructor. |

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/Lambda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class testLambda
99
delete [] r;
1010
};
1111

12-
r2 = new char[4096]; // GOOD [FALSE POSITIVE]
12+
r2 = new char[4096]; // GOOD
1313
auto deleter2 = [this]() {
1414
delete [] r2;
1515
};

0 commit comments

Comments
 (0)