C++: Update MemoryNeverFreed.ql to exclude alloca (and use the new allocation model directly).

This commit is contained in:
Geoffrey White
2019-12-17 11:10:03 +00:00
parent a8c31c6590
commit 9a944a947a
2 changed files with 7 additions and 12 deletions

View File

@@ -1,14 +1,7 @@
import semmle.code.cpp.pointsto.PointsTo
private predicate freed(Expr e) {
exists(FunctionCall fc, Expr arg |
freeCall(fc, arg) and
arg = e
)
or
exists(DeleteExpr de | de.getExpr() = e)
or
exists(DeleteArrayExpr de | de.getExpr() = e)
e = any(DeallocationExpr de).getFreedExpr()
or
exists(ExprCall c |
// cautiously assume that any ExprCall could be a freeCall.
@@ -22,7 +15,6 @@ class FreedExpr extends PointsToExpr {
override predicate interesting() { freed(this) }
}
predicate allocMayBeFreed(Expr alloc) {
isAllocationExpr(alloc) and
predicate allocMayBeFreed(AllocationExpr alloc) {
anythingPointsTo(alloc)
}

View File

@@ -11,6 +11,9 @@
import MemoryFreed
from Expr alloc
where isAllocationExpr(alloc) and not allocMayBeFreed(alloc)
from AllocationExpr alloc
where
alloc.requiresDealloc() and
not exists(alloc.(NewOrNewArrayExpr).getPlacementPointer()) and
not allocMayBeFreed(alloc)
select alloc, "This memory is never freed"