buff release check

This commit is contained in:
东煌 2020-09-12 19:10:18 +08:00
parent 093c391f57
commit d7e3ff804d

View File

@ -136,17 +136,15 @@ public class FrameDecoder extends ReplayingDecoder<FrameDecoder.State> {
}
case READ_BODY:
/*
* read the content-length specified
*/
final int contentLength = currentMessage.getContentLength();
final ByteBuf bodyBytes = buffer.readBytes(contentLength);
ByteBuf bodyBuff = null;
try {
log.debug("read [{}] body bytes", bodyBytes.writerIndex());
final int contentLength = currentMessage.getContentLength();
bodyBuff = buffer.readBytes(contentLength);
log.debug("read [{}] body bytes", bodyBuff.writerIndex());
// most bodies are line based, so split on LF
while (bodyBytes.isReadable()) {
final String bodyLine = readLine(bodyBytes, contentLength);
while (bodyBuff.isReadable()) {
final String bodyLine = readLine(bodyBuff, contentLength);
log.trace("read body line [{}]", bodyLine);
currentMessage.addBodyLine(bodyLine);
}
@ -159,9 +157,10 @@ public class FrameDecoder extends ReplayingDecoder<FrameDecoder.State> {
break;
}
finally {
bodyBytes.release();
if (bodyBuff != null) {
bodyBuff.release();
}
}
default:
throw new IllegalStateException("Illegal state: [" + state + ']');
}