Skip to content

Commit 90b1f42

Browse files
authored
Fix leaking blocks in TopN (#102715) (#102718)
Closes #102646
1 parent 2f9b964 commit 90b1f42

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

docs/changelog/102715.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 102715
2+
summary: Fix leaking blocks in TopN
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 102646

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/ResultBuilderForDoc.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.elasticsearch.compute.data.Block;
1212
import org.elasticsearch.compute.data.BlockFactory;
1313
import org.elasticsearch.compute.data.DocVector;
14+
import org.elasticsearch.compute.data.IntVector;
15+
import org.elasticsearch.core.Releasables;
1416

1517
class ResultBuilderForDoc implements ResultBuilder {
1618
private final BlockFactory blockFactory;
@@ -42,12 +44,21 @@ public void decodeValue(BytesRef values) {
4244

4345
@Override
4446
public Block build() {
45-
return new DocVector(
46-
blockFactory.newIntArrayVector(shards, position),
47-
blockFactory.newIntArrayVector(segments, position),
48-
blockFactory.newIntArrayVector(docs, position),
49-
null
50-
).asBlock();
47+
boolean success = false;
48+
IntVector shardsVector = null;
49+
IntVector segmentsVector = null;
50+
try {
51+
shardsVector = blockFactory.newIntArrayVector(shards, position);
52+
segmentsVector = blockFactory.newIntArrayVector(segments, position);
53+
var docsVector = blockFactory.newIntArrayVector(docs, position);
54+
var docsBlock = new DocVector(shardsVector, segmentsVector, docsVector, null).asBlock();
55+
success = true;
56+
return docsBlock;
57+
} finally {
58+
if (success == false) {
59+
Releasables.closeExpectNoException(shardsVector, segmentsVector);
60+
}
61+
}
5162
}
5263

5364
@Override

0 commit comments

Comments
 (0)