mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
C++: Update MemoryNeverFreed.ql to exclude alloca (and use the new allocation model directly).
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user