Skip to content

Commit 68bd164

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 2743aa1 commit 68bd164

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
import java.util.Stack;
5150

@@ -60,13 +59,13 @@
6059
* An XQuery 3.0 inline function expression.
6160
*
6261
* @author wolf
62+
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
6363
*/
6464
public class InlineFunction extends AbstractExpression {
6565

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

6868
private final UserDefinedFunction function;
69-
private final ArrayDeque<FunctionCall> calls = new ArrayDeque<>();
7069

7170
private AnalyzeContextInfo cachedContextInfo;
7271

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

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

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

0 commit comments

Comments
 (0)