Skip to content

Commit e7ebd05

Browse files
committed
Fix potential memory leak on circuit breaker error
1 parent f0349f4 commit e7ebd05

File tree

1 file changed

+11
-3
lines changed
  • x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash

1 file changed

+11
-3
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/LongTopNBlockHash.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@ final class LongTopNBlockHash extends BlockHash {
5050

5151
LongTopNBlockHash(int channel, boolean asc, boolean nullsFirst, int limit, BlockFactory blockFactory) {
5252
super(blockFactory);
53+
assert limit > 0 : "LongTopNBlockHash requires a limit greater than 0";
5354
this.channel = channel;
5455
this.asc = asc;
5556
this.nullsFirst = nullsFirst;
5657
this.limit = limit;
57-
this.hash = new LongHash(1, blockFactory.bigArrays());
58-
this.topValues = new LongTopNUniqueSort(blockFactory.bigArrays(), asc ? SortOrder.ASC : SortOrder.DESC, limit);
5958

60-
assert limit > 0 : "LongTopNBlockHash requires a limit greater than 0";
59+
boolean success = false;
60+
try {
61+
this.hash = new LongHash(1, blockFactory.bigArrays());
62+
this.topValues = new LongTopNUniqueSort(blockFactory.bigArrays(), asc ? SortOrder.ASC : SortOrder.DESC, limit);
63+
} finally {
64+
if (success == false) {
65+
close();
66+
}
67+
}
68+
6169
}
6270

6371
@Override

0 commit comments

Comments
 (0)