Skip to content

Commit 2f3a874

Browse files
committed
CPP: Fix false positives when a member variable is released via the target of a function pointer.
1 parent 370387a commit 2f3a874

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ predicate leakedInSameMethod(Resource r, Expr acquire) {
227227
fc.getQualifier() = r.getAnAccess() or // e.g. `r->setOwner(this)`
228228
fc = acquire.getAChild*() // e.g. `r = new MyClass(this)`
229229
)
230+
) or exists(FunctionAccess fa, string kind |
231+
// the address of a function that releases `r` is taken (and likely
232+
// used to release `r` at some point).
233+
r.acquisitionWithRequiredKind(acquire, kind) and
234+
fa.getTarget() = r.getAReleaseExpr(kind).getEnclosingFunction()
230235
)
231236
)
232237
}

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:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
14-
| 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. |
1514
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1615
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
1716
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |

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
@@ -26,7 +26,7 @@ class testLambda
2626
r5 = new char[4096]; // GOOD
2727
deleter5 = &deleter_for_r5;
2828

29-
r6 = new char[4096]; // GOOD [FALSE POSITIVE]
29+
r6 = new char[4096]; // GOOD
3030
deleter6 = &testLambda::deleter_for_r6;
3131
}
3232

0 commit comments

Comments
 (0)