Skip to content

Commit

Permalink
Only acquire buffer when need write. (apache#3786)
Browse files Browse the repository at this point in the history
### Motivation
small fix: when ByteBuf size is zero. the acquired buffer is not released.
  • Loading branch information
lifepuzzlefun authored and Anup Ghatage committed Jul 12, 2024
1 parent 62cfe23 commit 813a4e0
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ public void writeAt(long offset, ByteBuf buf) throws IOException {
checkArgument(Buffer.isAligned(buf.readableBytes()),
"Buffer must write multiple of alignment bytes (%d), %d is not",
Buffer.ALIGNMENT, buf.readableBytes());
Buffer tmpBuffer = bufferPool.acquire();

int bytesToWrite = buf.readableBytes();
if (bytesToWrite <= 0) {
return;
}

Buffer tmpBuffer = bufferPool.acquire();
tmpBuffer.reset();
tmpBuffer.writeByteBuf(buf);
Future<?> f = writeExecutor.submit(() -> {
Expand Down

0 comments on commit 813a4e0

Please sign in to comment.