Skip to content

Commit

Permalink
Fix memory leak issue in ReorganizingLongHash
Browse files Browse the repository at this point in the history
Signed-off-by: Neetika Singhal <[email protected]>
  • Loading branch information
neetikasinghal committed Jan 19, 2024
1 parent e265355 commit bb99414
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ 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);
boolean success = false;
try {
table = bigArrays.newLongArray(capacity, false);
table.fill(0, capacity, -1); // -1 represents an empty slot
keys = bigArrays.newLongArray(initialCapacity, false);
success = true;
} finally {
if (!success) {
// 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 bb99414

Please sign in to comment.