Skip to content

Commit 35633a8

Browse files
authored
Fix potential block leak in LuceneSourceOperator (#123835) (#123838)
A follow-up to #123296 to address a potential block leak that may occur when a circuit-breaking exception is triggered while truncating the docs or scores blocks. Relates #123296 (cherry picked from commit 7560e2e)
1 parent 5ed6a84 commit 35633a8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneSourceOperator.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ private IntVector buildDocsVector(int upToPositions) {
232232
if (docs.getPositionCount() == upToPositions) {
233233
return docs;
234234
}
235-
try (var slice = blockFactory.newIntVectorFixedBuilder(upToPositions)) {
236-
for (int i = 0; i < upToPositions; i++) {
237-
slice.appendInt(docs.getInt(i));
235+
try (docs) {
236+
try (var slice = blockFactory.newIntVectorFixedBuilder(upToPositions)) {
237+
for (int i = 0; i < upToPositions; i++) {
238+
slice.appendInt(docs.getInt(i));
239+
}
240+
return slice.build();
238241
}
239-
docs.close();
240-
return slice.build();
241242
}
242243
}
243244

@@ -247,12 +248,13 @@ private DoubleVector buildScoresVector(int upToPositions) {
247248
if (scores.getPositionCount() == upToPositions) {
248249
return scores;
249250
}
250-
try (var slice = blockFactory.newDoubleVectorBuilder(upToPositions)) {
251-
for (int i = 0; i < upToPositions; i++) {
252-
slice.appendDouble(scores.getDouble(i));
251+
try (scores) {
252+
try (var slice = blockFactory.newDoubleVectorBuilder(upToPositions)) {
253+
for (int i = 0; i < upToPositions; i++) {
254+
slice.appendDouble(scores.getDouble(i));
255+
}
256+
return slice.build();
253257
}
254-
scores.close();
255-
return slice.build();
256258
}
257259
}
258260

0 commit comments

Comments
 (0)