Skip to content

Commit b861df0

Browse files
committed
CPP: Fix issue when destructor body is missing.
1 parent 5931a97 commit b861df0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ predicate unreleasedResource(Resource r, Expr acquire, File f, int acquireLine)
159159
)
160160
and f = acquire.getFile()
161161
and acquireLine = acquire.getLocation().getStartLine()
162+
163+
// check that any destructor for this class has a block; if it doesn't,
164+
// we must be missing information.
165+
and forall(Destructor d |
166+
d = r.getDeclaringType().getAMember() and
167+
not d.isCompilerGenerated() |
168+
exists(d.getBlock())
169+
)
162170
}
163171

164172
predicate freedInSameMethod(Resource r, Expr acquire) {

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
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
1212
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1313
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
14-
| NoDestructor.cpp:75:3:75:21 | ... = ... | Resource ptr is acquired by class TemplateWithDestructor<int *> but not released anywhere in this class. |
1514
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
1615
| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
1716
| Variants.cpp:25:3:25:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TemplateWithDestructor
7272
{
7373
public:
7474
TemplateWithDestructor(int len) {
75-
ptr = new char[len]; // GOOD [FALSE POSITIVE]
75+
ptr = new char[len]; // GOOD
7676
}
7777

7878
~TemplateWithDestructor()

0 commit comments

Comments
 (0)