[#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) {
|
} else if (msg instanceof HttpMessage) {
|
||||||
HttpMessage m = (HttpMessage) msg;
|
HttpMessage m = (HttpMessage) msg;
|
||||||
|
|
||||||
if (decoder != null) {
|
cleanup();
|
||||||
// Clean-up the previous decoder if not cleaned up correctly.
|
|
||||||
finishDecode(Unpooled.buffer());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the content encoding.
|
// Determine the content encoding.
|
||||||
String contentEncoding = m.getHeader(HttpHeaders.Names.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;
|
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) {
|
private void decode(ByteBuf in, ByteBuf out) {
|
||||||
decoder.writeInbound(in);
|
decoder.writeInbound(in);
|
||||||
fetchDecoderOutput(out);
|
fetchDecoderOutput(out);
|
||||||
|
@ -88,10 +88,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
|||||||
} else if (msg instanceof HttpMessage) {
|
} else if (msg instanceof HttpMessage) {
|
||||||
HttpMessage m = (HttpMessage) msg;
|
HttpMessage m = (HttpMessage) msg;
|
||||||
|
|
||||||
if (encoder != null) {
|
cleanup();
|
||||||
// Clean-up the previous encoder if not cleaned up correctly.
|
|
||||||
finishEncode(Unpooled.buffer());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the content encoding.
|
// Determine the content encoding.
|
||||||
String acceptEncoding = acceptEncodingQueue.poll();
|
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;
|
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) {
|
private void encode(ByteBuf in, ByteBuf out) {
|
||||||
encoder.writeOutbound(in);
|
encoder.writeOutbound(in);
|
||||||
fetchEncoderOutput(out);
|
fetchEncoderOutput(out);
|
||||||
|
Loading…
Reference in New Issue
Block a user