Skip to content

Commit 780b2d2

Browse files
Fix memory leak issue in ReorganizingLongHash
Signed-off-by: Neetika Singhal <neetiks@amazon.com>
1 parent e265355 commit 780b2d2

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
236236
- Fix issue when calling Delete PIT endpoint and no PITs exist ([#11711](https://github.com/opensearch-project/OpenSearch/pull/11711))
237237
- Fix tracing context propagation for local transport instrumentation ([#11490](https://github.com/opensearch-project/OpenSearch/pull/11490))
238238
- Fix parsing of single line comments in `lang-painless` ([#11815](https://github.com/opensearch-project/OpenSearch/issues/11815))
239+
- Fix memory leak issue in ReorganizingLongHash ([#11953](https://github.com/opensearch-project/OpenSearch/issues/11953))
239240

240241
### Security
241242

server/src/main/java/org/opensearch/common/util/ReorganizingLongHash.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,19 @@ public ReorganizingLongHash(final long initialCapacity, final float loadFactor,
118118
mask = capacity - 1;
119119
grow = (long) (capacity * loadFactor);
120120
size = 0;
121-
122-
table = bigArrays.newLongArray(capacity, false);
123-
table.fill(0, capacity, -1); // -1 represents an empty slot
124-
keys = bigArrays.newLongArray(initialCapacity, false);
121+
boolean success = false;
122+
try {
123+
table = bigArrays.newLongArray(capacity, false);
124+
table.fill(0, capacity, -1); // -1 represents an empty slot
125+
keys = bigArrays.newLongArray(initialCapacity, false);
126+
success = true;
127+
} finally {
128+
if (!success) {
129+
// it's important to close the arrays initialized above to prevent memory leak
130+
// refer: https://github.com/opensearch-project/OpenSearch/issues/10154
131+
Releasables.closeWhileHandlingException(table, keys);
132+
}
133+
}
125134
}
126135

127136
/**

0 commit comments

Comments
 (0)