Skip to content

Commit 6a37eca

Browse files
committed
Ensure CannedSourceOperator::deepCopyOf properly release blocks on failure.
1 parent 5f0fb60 commit 6a37eca

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/CannedSourceOperator.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,20 @@ public static List<Page> deepCopyOf(BlockFactory blockFactory, List<Page> pages)
8484
try {
8585
for (Page p : pages) {
8686
Block[] blocks = new Block[p.getBlockCount()];
87-
for (int b = 0; b < blocks.length; b++) {
88-
Block orig = p.getBlock(b);
89-
try (Block.Builder builder = orig.elementType().newBlockBuilder(p.getPositionCount(), blockFactory)) {
90-
builder.copyFrom(orig, 0, p.getPositionCount());
91-
blocks[b] = builder.build();
87+
try {
88+
for (int b = 0; b < blocks.length; b++) {
89+
Block orig = p.getBlock(b);
90+
try (Block.Builder builder = orig.elementType().newBlockBuilder(p.getPositionCount(), blockFactory)) {
91+
builder.copyFrom(orig, 0, p.getPositionCount());
92+
blocks[b] = builder.build();
93+
}
9294
}
95+
out.add(new Page(blocks));
96+
} catch (Exception e) {
97+
// Something went wrong, release the blocks.
98+
Releasables.closeExpectNoException(blocks);
99+
throw e;
93100
}
94-
out.add(new Page(blocks));
95101
}
96102
} finally {
97103
if (pages.size() != out.size()) {

0 commit comments

Comments
 (0)