Skip to content

Commit 1be9762

Browse files
authored
Merge pull request #1162 from geoffw0/rnr-open
CPP: Fix Resource not released in destructor FP
2 parents 4d1161f + 2759861 commit 1be9762

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

change-notes/1.21/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
| **Query** | **Expected impact** | **Change** |
1313
|----------------------------|------------------------|------------------------------------------------------------------|
1414
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed an issue where functions were being identified as allocation functions inappropriately. Also affects `cpp/new-array-delete-mismatch` and `cpp/new-delete-array-mismatch`. |
15+
| Resource not released in destructor (`cpp/resource-not-released-in-destructor`) | Fewer false positive results | Resource allocation and deallocation functions are now determined more accurately. |
1516

1617
## Changes to QL libraries

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ predicate acquireExpr(Expr acquire, string kind) {
2121
exists(FunctionCall fc, Function f, string name |
2222
fc = acquire and
2323
f = fc.getTarget() and
24-
name = f.getName() and
24+
name = f.getQualifiedName() and
2525
(
2626
(
2727
name = "fopen" and
@@ -47,7 +47,7 @@ predicate releaseExpr(Expr release, Expr resource, string kind) {
4747
exists(FunctionCall fc, Function f, string name |
4848
fc = release and
4949
f = fc.getTarget() and
50-
name = f.getName() and
50+
name = f.getQualifiedName() and
5151
(
5252
(
5353
name = "fclose" and

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,39 @@ class MyClass6
7373

7474
int *a, *b, *c;
7575
};
76+
77+
class MyClass7
78+
{
79+
public:
80+
MyClass7()
81+
{
82+
}
83+
84+
bool open()
85+
{
86+
// ...
87+
}
88+
89+
void close()
90+
{
91+
// ...
92+
}
93+
};
94+
95+
class myClass7Test
96+
{
97+
public:
98+
myClass7Test()
99+
{
100+
success = mc7.open(); // GOOD
101+
}
102+
103+
~myClass7Test()
104+
{
105+
mc7.close();
106+
}
107+
108+
private:
109+
MyClass7 mc7;
110+
bool success;
111+
};

0 commit comments

Comments
 (0)