Skip to content

Commit

Permalink
AdaptivePoolingAllocator: Resolve the release issue of the currentChu…
Browse files Browse the repository at this point in the history
…nk (netty#14348)

Motivation:

When the capacity of `currentChunk` is less than or equal to that of
`nextChunk`,
 `currentChunk` is not released.

Modification:

When the capacity of `currentChunk` is less than or equal to that of
`nextChunk`,
release the currentChunk.

Result:

Prevent memory leaks
  • Loading branch information
CLFutureX authored Sep 19, 2024
1 parent 42e29e2 commit 1967ad4
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,15 @@ private void transferChunk(Chunk current) {
Chunk nextChunk = NEXT_IN_LINE.get(this);
if (nextChunk != null && current.remainingCapacity() > nextChunk.remainingCapacity()) {
if (NEXT_IN_LINE.compareAndSet(this, nextChunk, current)) {
nextChunk.release();
} else {
// Next-in-line is occupied AND the central queue is full.
// Rare that we should get here, but we'll only do one allocation out of this chunk, then.
current.release();
if (nextChunk != MAGAZINE_FREED) {
nextChunk.release();
}
return;
}
}
// Next-in-line is occupied AND the central queue is full.
// Rare that we should get here, but we'll only do one allocation out of this chunk, then.
current.release();
}

private Chunk newChunkAllocation(int promptingSize) {
Expand Down

0 comments on commit 1967ad4

Please sign in to comment.