Skip to content

Commit

Permalink
Only acquire buffer when need write. (#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 Feb 21, 2023
1 parent 5726e8f commit 13ccc4c
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 13ccc4c

Please sign in to comment.