[#1067] Fix bug which can cause IllegalBufferAccessException when using aggregator and deflater the same time

This commit is contained in:
Norman Maurer 2013-02-21 06:48:53 +01:00
parent c93f5afa99
commit 00310d96af

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.ReferenceCounted;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
@ -63,15 +64,22 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
} }
boolean offered = acceptEncodingQueue.offer(acceptedEncoding); boolean offered = acceptEncodingQueue.offer(acceptedEncoding);
assert offered; assert offered;
if (msg instanceof ReferenceCounted) {
// need to call retain to not free it
((ReferenceCounted) msg).retain();
}
return msg; return msg;
} }
@Override @Override
protected Object encode(ChannelHandlerContext ctx, HttpObject msg) protected Object encode(ChannelHandlerContext ctx, HttpObject msg)
throws Exception { throws Exception {
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().code() == 100) { if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().code() == 100) {
// 100-continue response must be passed through. // 100-continue response must be passed through.
if (msg instanceof ReferenceCounted) {
// need to call retain to not free it
((ReferenceCounted) msg).retain();
}
return msg; return msg;
} }
@ -84,7 +92,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
throw new IllegalStateException("cannot send more responses than requests"); throw new IllegalStateException("cannot send more responses than requests");
} }
return msg; return ((FullHttpMessage) msg).retain();
} }
if (msg instanceof HttpMessage) { if (msg instanceof HttpMessage) {
@ -163,8 +171,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
return encodeContent(null, c); return encodeContent(null, c);
} }
c.retain(); return c.retain();
return c;
} }
return null; return null;
} }