Skip to content

Commit

Permalink
Fix leaking blocks in TopN (#102715) (#102718)
Browse files Browse the repository at this point in the history
Closes #102646
  • Loading branch information
dnhatn committed Nov 28, 2023
1 parent 2f9b964 commit 90b1f42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/102715.yaml
@@ -0,0 +1,6 @@
pr: 102715
summary: Fix leaking blocks in TopN
area: ES|QL
type: bug
issues:
- 102646
Expand Up @@ -11,6 +11,8 @@
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.DocVector;
import org.elasticsearch.compute.data.IntVector;
import org.elasticsearch.core.Releasables;

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

@Override
public Block build() {
return new DocVector(
blockFactory.newIntArrayVector(shards, position),
blockFactory.newIntArrayVector(segments, position),
blockFactory.newIntArrayVector(docs, position),
null
).asBlock();
boolean success = false;
IntVector shardsVector = null;
IntVector segmentsVector = null;
try {
shardsVector = blockFactory.newIntArrayVector(shards, position);
segmentsVector = blockFactory.newIntArrayVector(segments, position);
var docsVector = blockFactory.newIntArrayVector(docs, position);
var docsBlock = new DocVector(shardsVector, segmentsVector, docsVector, null).asBlock();
success = true;
return docsBlock;
} finally {
if (success == false) {
Releasables.closeExpectNoException(shardsVector, segmentsVector);
}
}
}

@Override
Expand Down

0 comments on commit 90b1f42

Please sign in to comment.