Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a944a9

Browse files
committed
C++: Update MemoryNeverFreed.ql to exclude alloca (and use the new allocation model directly).
1 parent a8c31c6 commit 9a944a9

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import semmle.code.cpp.pointsto.PointsTo
22

33
private predicate freed(Expr e) {
4-
exists(FunctionCall fc, Expr arg |
5-
freeCall(fc, arg) and
6-
arg = e
7-
)
8-
or
9-
exists(DeleteExpr de | de.getExpr() = e)
10-
or
11-
exists(DeleteArrayExpr de | de.getExpr() = e)
4+
e = any(DeallocationExpr de).getFreedExpr()
125
or
136
exists(ExprCall c |
147
// cautiously assume that any ExprCall could be a freeCall.
@@ -22,7 +15,6 @@ class FreedExpr extends PointsToExpr {
2215
override predicate interesting() { freed(this) }
2316
}
2417

25-
predicate allocMayBeFreed(Expr alloc) {
26-
isAllocationExpr(alloc) and
18+
predicate allocMayBeFreed(AllocationExpr alloc) {
2719
anythingPointsTo(alloc)
2820
}

cpp/ql/src/Critical/MemoryNeverFreed.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import MemoryFreed
1313

14-
from Expr alloc
15-
where isAllocationExpr(alloc) and not allocMayBeFreed(alloc)
14+
from AllocationExpr alloc
15+
where
16+
alloc.requiresDealloc() and
17+
not exists(alloc.(NewOrNewArrayExpr).getPlacementPointer()) and
18+
not allocMayBeFreed(alloc)
1619
select alloc, "This memory is never freed"

0 commit comments

Comments
 (0)