CPP: Make references to the 'kind' of an alloc/delete consistent (this used to be called the 'release' or 'releaseName').

This commit is contained in:
Geoffrey White
2018-12-11 22:55:43 +00:00
parent 8e2459a6b7
commit 6efd481118

View File

@@ -140,12 +140,12 @@ class Resource extends MemberVariable {
)
}
predicate acquisitionWithRequiredRelease(Assignment acquireAssign, string kind) {
predicate acquisitionWithRequiredKind(Assignment acquireAssign, string kind) {
// acquireAssign is an assignment to this resource
acquireAssign.(Assignment).getLValue() = this.getAnAccess() and
// Should be in this class, but *any* member method will do
this.inSameClass(acquireAssign) and
// Check that it is an acquisition function and return the corresponding free
// Check that it is an acquisition function and return the corresponding kind
acquireExpr(acquireAssign.getRValue(), kind)
}
@@ -158,10 +158,10 @@ predicate unreleasedResource(Resource r, Expr acquire, File f, int acquireLine)
// Note: there could be several release functions, because there could be
// several functions called 'fclose' for example. We want to check that
// *none* of these functions are called to release the resource
r.acquisitionWithRequiredRelease(acquire, _) and
not exists(Expr releaseExpr, string releaseName |
r.acquisitionWithRequiredRelease(acquire, releaseName) and
releaseExpr = r.getAReleaseExpr(releaseName) and
r.acquisitionWithRequiredKind(acquire, _) and
not exists(Expr releaseExpr, string kind |
r.acquisitionWithRequiredKind(acquire, kind) and
releaseExpr = r.getAReleaseExpr(kind) and
r.inDestructor(releaseExpr)
)
and f = acquire.getFile()
@@ -181,9 +181,9 @@ predicate unreleasedResource(Resource r, Expr acquire, File f, int acquireLine)
predicate freedInSameMethod(Resource r, Expr acquire) {
unreleasedResource(r, acquire, _, _) and
exists(Expr releaseExpr, string releaseName |
r.acquisitionWithRequiredRelease(acquire, releaseName) and
releaseExpr = r.getAReleaseExpr(releaseName) and
exists(Expr releaseExpr, string kind |
r.acquisitionWithRequiredKind(acquire, kind) and
releaseExpr = r.getAReleaseExpr(kind) and
releaseExpr.getEnclosingFunction() = acquire.getEnclosingFunction()
)
}
@@ -224,10 +224,10 @@ predicate leakedInSameMethod(Resource r, Expr acquire) {
pragma[noopt] predicate badRelease(Resource r, Expr acquire, Function functionCallingRelease, int line) {
unreleasedResource(r, acquire, _, _) and
exists(Expr releaseExpr, string releaseName,
exists(Expr releaseExpr, string kind,
Location releaseExprLocation, Function acquireFunction |
r.acquisitionWithRequiredRelease(acquire, releaseName) and
releaseExpr = r.getAReleaseExpr(releaseName) and
r.acquisitionWithRequiredKind(acquire, kind) and
releaseExpr = r.getAReleaseExpr(kind) and
releaseExpr.getEnclosingFunction() = functionCallingRelease and
functionCallingRelease.getDeclaringType() = r.getDeclaringType() and
releaseExprLocation = releaseExpr.getLocation() and