Ensure we null out cumulation buffer before fire through the pipeline in handlerRemoved(...)

Motivation:

We should ensure we null out the cumulation buffer before we fire it through the pipleine in handlerRemoved(...) as in theory it could be possible that another method is triggered as result of the fireChannelRead(...) or fireChannelReadComplete() that will try to access the cumulation.

Modifications:

Null out cumulation buffer early in handlerRemoved(...)

Result:

No possible to access the cumulation buffer that was already handed over.
This commit is contained in:
Norman Maurer 2016-06-03 15:12:32 +02:00
parent e847ac0443
commit dc816e9807
2 changed files with 16 additions and 12 deletions

View File

@ -207,18 +207,23 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
@Override
public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
ByteBuf buf = internalBuffer();
int readable = buf.readableBytes();
if (readable > 0) {
ByteBuf bytes = buf.readBytes(readable);
buf.release();
ctx.fireChannelRead(bytes);
} else {
buf.release();
ByteBuf buf = cumulation;
if (buf != null) {
// Directly set this to null so we are sure we not access it in any other method here anymore.
cumulation = null;
int readable = buf.readableBytes();
if (readable > 0) {
ByteBuf bytes = buf.readBytes(readable);
buf.release();
ctx.fireChannelRead(bytes);
} else {
buf.release();
}
numReads = 0;
ctx.fireChannelReadComplete();
}
cumulation = null;
numReads = 0;
ctx.fireChannelReadComplete();
handlerRemoved0(ctx);
}

View File

@ -21,7 +21,6 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.util.Signal;
import io.netty.util.internal.RecyclableArrayList;
import io.netty.util.internal.StringUtil;
import java.util.List;