Merge pull request #15120 from MathiasVP/fix-joins-in-av-rule-79

C++: Fix joins in `cpp/resource-not-released-in-destructor`
This commit is contained in:
Mathias Vorreiter Pedersen
2023-12-15 14:06:53 +00:00
committed by GitHub
2 changed files with 6 additions and 9 deletions

View File

@@ -328,6 +328,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
MetricFunction getMetrics() { result = this }
/** Holds if this function calls the function `f`. */
pragma[nomagic]
predicate calls(Function f) { this.calls(f, _) }
/**
@@ -338,10 +339,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
exists(FunctionCall call |
call.getEnclosingFunction() = this and call.getTarget() = f and call = l
)
or
exists(DestructorCall call |
call.getEnclosingFunction() = this and call.getTarget() = f and call = l
)
}
/** Holds if this function accesses a function or variable or enumerator `a`. */

View File

@@ -126,13 +126,13 @@ class Resource extends MemberVariable {
}
private predicate calledFromDestructor(Function f) {
f instanceof Destructor and f.getDeclaringType() = this.getDeclaringType()
pragma[only_bind_into](f) instanceof Destructor and
f.getDeclaringType() = this.getDeclaringType()
or
exists(Function mid, FunctionCall fc |
exists(Function mid |
this.calledFromDestructor(mid) and
fc.getEnclosingFunction() = mid and
fc.getTarget() = f and
f.getDeclaringType() = this.getDeclaringType()
mid.calls(f) and
pragma[only_bind_out](f.getDeclaringType()) = pragma[only_bind_out](this.getDeclaringType())
)
}