[#539] Potential direct memory leak in HttpContentEn/Decoder
This commit is contained in:
parent
df0aee22cb
commit
ec2b29f0b6
@ -63,10 +63,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
} else if (msg instanceof HttpMessage) {
|
||||
HttpMessage m = (HttpMessage) msg;
|
||||
|
||||
if (decoder != null) {
|
||||
// Clean-up the previous decoder if not cleaned up correctly.
|
||||
finishDecode(Unpooled.buffer());
|
||||
}
|
||||
cleanup();
|
||||
|
||||
// Determine the content encoding.
|
||||
String contentEncoding = m.getHeader(HttpHeaders.Names.CONTENT_ENCODING);
|
||||
@ -155,6 +152,25 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
return HttpHeaders.Values.IDENTITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
||||
cleanup();
|
||||
super.afterRemove(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
cleanup();
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (decoder != null) {
|
||||
// Clean-up the previous decoder if not cleaned up correctly.
|
||||
finishDecode(Unpooled.buffer());
|
||||
}
|
||||
}
|
||||
|
||||
private void decode(ByteBuf in, ByteBuf out) {
|
||||
decoder.writeInbound(in);
|
||||
fetchDecoderOutput(out);
|
||||
|
@ -88,10 +88,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
} else if (msg instanceof HttpMessage) {
|
||||
HttpMessage m = (HttpMessage) msg;
|
||||
|
||||
if (encoder != null) {
|
||||
// Clean-up the previous encoder if not cleaned up correctly.
|
||||
finishEncode(Unpooled.buffer());
|
||||
}
|
||||
cleanup();
|
||||
|
||||
// Determine the content encoding.
|
||||
String acceptEncoding = acceptEncodingQueue.poll();
|
||||
@ -179,6 +176,26 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
*/
|
||||
protected abstract Result beginEncode(HttpMessage msg, String acceptEncoding) throws Exception;
|
||||
|
||||
|
||||
@Override
|
||||
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
||||
cleanup();
|
||||
super.afterRemove(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
cleanup();
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (encoder != null) {
|
||||
// Clean-up the previous encoder if not cleaned up correctly.
|
||||
finishEncode(Unpooled.buffer());
|
||||
}
|
||||
}
|
||||
|
||||
private void encode(ByteBuf in, ByteBuf out) {
|
||||
encoder.writeOutbound(in);
|
||||
fetchEncoderOutput(out);
|
||||
|
Loading…
Reference in New Issue
Block a user