Skip to content

Commit

Permalink
Fix memory leak issue in ReorganizingLongHash (#11953) (#11955)
Browse files Browse the repository at this point in the history
Signed-off-by: Neetika Singhal <[email protected]>
(cherry picked from commit 84f303b)
  • Loading branch information
neetikasinghal authored Jan 20, 2024
1 parent c0581a0 commit a93e86c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix tracing context propagation for local transport instrumentation ([#11490](https://github.com/opensearch-project/OpenSearch/pull/11490))
- Fix parsing of single line comments in `lang-painless` ([#11815](https://github.com/opensearch-project/OpenSearch/issues/11815))
- Fix typo in API annotation check message ([11836](https://github.com/opensearch-project/OpenSearch/pull/11836))
- Fix memory leak issue in ReorganizingLongHash ([#11953](https://github.com/opensearch-project/OpenSearch/issues/11953))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,17 @@ public ReorganizingLongHash(final long initialCapacity, final float loadFactor,
mask = capacity - 1;
grow = (long) (capacity * loadFactor);
size = 0;

table = bigArrays.newLongArray(capacity, false);
table.fill(0, capacity, -1); // -1 represents an empty slot
keys = bigArrays.newLongArray(initialCapacity, false);
try {
table = bigArrays.newLongArray(capacity, false);
table.fill(0, capacity, -1); // -1 represents an empty slot
keys = bigArrays.newLongArray(initialCapacity, false);
} finally {
if (table == null || keys == null) {
// it's important to close the arrays initialized above to prevent memory leak
// refer: https://github.com/opensearch-project/OpenSearch/issues/10154
Releasables.closeWhileHandlingException(table, keys);
}
}
}

/**
Expand Down

0 comments on commit a93e86c

Please sign in to comment.