Skip to content

Commit 4bff560

Browse files
committed
[bugfix] Ensure that inline (anonymous) functions do not accumulate closures, and that these are not leaked if the query is cached for reuse
1 parent 0c650d3 commit 4bff560

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

exist-core/src/main/java/org/exist/xquery/InlineFunction.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*/
4646
package org.exist.xquery;
4747

48-
import java.util.ArrayDeque;
4948
import java.util.List;
5049

5150
import org.exist.dom.QName;
@@ -59,13 +58,13 @@
5958
* An XQuery 3.0 inline function expression.
6059
*
6160
* @author wolf
61+
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
6262
*/
6363
public class InlineFunction extends AbstractExpression {
6464

6565
public static final QName INLINE_FUNCTION_QNAME = QName.EMPTY_QNAME;
6666

6767
private final UserDefinedFunction function;
68-
private final ArrayDeque<FunctionCall> calls = new ArrayDeque<>();
6968

7069
private AnalyzeContextInfo cachedContextInfo;
7170

@@ -102,10 +101,6 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
102101
call.setLocation(function.getLine(), function.getColumn());
103102
call.analyze(new AnalyzeContextInfo(cachedContextInfo));
104103

105-
// push the created function call to the stack so we can clear
106-
// it after execution
107-
calls.push(call);
108-
109104
return new FunctionReference(this, call);
110105
}
111106

@@ -117,7 +112,11 @@ public int returnsType() {
117112
@Override
118113
public void resetState(final boolean postOptimization) {
119114
super.resetState(postOptimization);
120-
calls.clear();
115+
116+
if (!postOptimization) {
117+
function.setClosureVariables(null);
118+
}
119+
121120
function.resetState(postOptimization);
122121
}
123122
}

0 commit comments

Comments
 (0)