Skip to content

Commit 370387a

Browse files
committed
CPP: Fix false positives when member variable is released via an ExprCall.
1 parent e408f18 commit 370387a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ predicate unreleasedResource(Resource r, Expr acquire, File f, int acquireLine)
167167
and f = acquire.getFile()
168168
and acquireLine = acquire.getLocation().getStartLine()
169169

170+
and not exists(ExprCall exprCall |
171+
// expression call (function pointer or lambda) with `r` as an
172+
// argument, which could release it.
173+
exprCall.getAnArgument() = r.getAnAccess() and
174+
r.inDestructor(exprCall)
175+
)
176+
170177
// check that any destructor for this class has a block; if it doesn't,
171178
// we must be missing information.
172179
and forall(Class c, Destructor d |

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
| DeleteThis.cpp:60:3:60:24 | ... = ... | Resource ptr14 is acquired by class MyClass3 but not released anywhere in this class. |
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. |
13-
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
1413
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
15-
| Lambda.cpp:26:3:26:21 | ... = ... | Resource r5 is acquired by class testLambda but not released anywhere in this class. |
1614
| 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. |
1715
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1816
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class testLambda
44
public:
55
testLambda()
66
{
7-
r1 = new char[4096]; // GOOD [FALSE POSITIVE]
7+
r1 = new char[4096]; // GOOD
88
deleter1 = [](char *r) {
99
delete [] r;
1010
};
@@ -23,7 +23,7 @@ class testLambda
2323

2424
r4 = new char[4096]; // BAD
2525

26-
r5 = new char[4096]; // GOOD [FALSE POSITIVE]
26+
r5 = new char[4096]; // GOOD
2727
deleter5 = &deleter_for_r5;
2828

2929
r6 = new char[4096]; // GOOD [FALSE POSITIVE]

0 commit comments

Comments
 (0)