Merge pull request #580 from geoffw0/av-79-perf

CPP: Fix performance issue with AV Rule 79.ql.
This commit is contained in:
Jonas Jensen
2018-11-30 08:39:38 +01:00
committed by GitHub

View File

@@ -189,24 +189,26 @@ predicate freedInSameMethod(Resource r, Expr acquire) {
*/
predicate leakedInSameMethod(Resource r, Expr acquire) {
unreleasedResource(r, acquire, _, _) and
exists(Function f |
acquire.getEnclosingFunction() = f and
(
exists(FunctionCall fc |
// `r` (or something computed from it) is passed to another function
// near to where it's acquired, and might be stored elsewhere.
fc.getAnArgument().getAChild*() = r.getAnAccess() and
fc.getEnclosingFunction() = acquire.getEnclosingFunction()
fc.getEnclosingFunction() = f
) or exists(Variable v, Expr e |
// `r` (or something computed from it) is stored in another variable
// near to where it's acquired, and might be released through that
// variable.
v.getAnAssignedValue() = e and
e.getAChild*() = r.getAnAccess() and
e.getEnclosingFunction() = acquire.getEnclosingFunction()
e.getEnclosingFunction() = f
) or exists(FunctionCall fc |
// `this` (i.e. the class where `r` is acquired) is passed into `r` via a
// method, or the constructor. `r` may use this to register itself with
// `this` in some way, ensuring it is later deleted.
fc.getEnclosingFunction() = acquire.getEnclosingFunction() and
fc.getEnclosingFunction() = f and
fc.getAnArgument() instanceof ThisExpr and
(
fc.getQualifier() = r.getAnAccess() or // e.g. `r->setOwner(this)`
@@ -214,6 +216,7 @@ predicate leakedInSameMethod(Resource r, Expr acquire) {
)
)
)
)
}
pragma[noopt] predicate badRelease(Resource r, Expr acquire, Function functionCallingRelease, int line) {