Skip to content

Commit dc9c538

Browse files
authored
Merge pull request #15120 from MathiasVP/fix-joins-in-av-rule-79
C++: Fix joins in `cpp/resource-not-released-in-destructor`
2 parents 3977689 + 2c5f65a commit dc9c538

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

cpp/ql/lib/semmle/code/cpp/Function.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
328328
MetricFunction getMetrics() { result = this }
329329

330330
/** Holds if this function calls the function `f`. */
331+
pragma[nomagic]
331332
predicate calls(Function f) { this.calls(f, _) }
332333

333334
/**
@@ -338,10 +339,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
338339
exists(FunctionCall call |
339340
call.getEnclosingFunction() = this and call.getTarget() = f and call = l
340341
)
341-
or
342-
exists(DestructorCall call |
343-
call.getEnclosingFunction() = this and call.getTarget() = f and call = l
344-
)
345342
}
346343

347344
/** Holds if this function accesses a function or variable or enumerator `a`. */

cpp/ql/src/jsf/4.10 Classes/AV Rule 79.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ class Resource extends MemberVariable {
126126
}
127127

128128
private predicate calledFromDestructor(Function f) {
129-
f instanceof Destructor and f.getDeclaringType() = this.getDeclaringType()
129+
pragma[only_bind_into](f) instanceof Destructor and
130+
f.getDeclaringType() = this.getDeclaringType()
130131
or
131-
exists(Function mid, FunctionCall fc |
132+
exists(Function mid |
132133
this.calledFromDestructor(mid) and
133-
fc.getEnclosingFunction() = mid and
134-
fc.getTarget() = f and
135-
f.getDeclaringType() = this.getDeclaringType()
134+
mid.calls(f) and
135+
pragma[only_bind_out](f.getDeclaringType()) = pragma[only_bind_out](this.getDeclaringType())
136136
)
137137
}
138138

0 commit comments

Comments
 (0)