Skip to content

Commit

Permalink
修复文件上传过程中的一处byteBuff泄漏
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziwen committed Jul 10, 2021
1 parent 3365535 commit 3e62349
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.handler.traffic.ChannelTrafficShapingHandler;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.Promise;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -203,8 +204,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
}
ByteBuf buffer = (ByteBuf) msg;
int length = 0;
while ((length = buffer.readableBytes()) > 0) {
buffer.readBytes(uploadFileInfo.getFileChannel(), uploadFileInfo.getAndAddOffset(length), length);
try {
while ((length = buffer.readableBytes()) > 0) {
buffer.readBytes(uploadFileInfo.getFileChannel(), uploadFileInfo.getAndAddOffset(length), length);
}
} finally {
ReferenceCountUtil.release(buffer);
}
}

Expand Down

0 comments on commit 3e62349

Please sign in to comment.