From a93ada203131b22fdc93945147e231566b87d7a6 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 20 Aug 2012 13:40:58 +0900 Subject: [PATCH] [#539] Potential direct memory leak in HttpContentEn/Decoder --- .../codec/http/HttpContentDecoder.java | 20 ++++++++++++++++++- .../codec/http/HttpContentEncoder.java | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpContentDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpContentDecoder.java index 1202085a4e..36d5137a12 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpContentDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpContentDecoder.java @@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; +import org.jboss.netty.channel.LifeCycleAwareChannelHandler; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelUpstreamHandler; import org.jboss.netty.handler.codec.embedder.DecoderEmbedder; @@ -43,7 +44,8 @@ import org.jboss.netty.handler.codec.embedder.DecoderEmbedder; * so that this handler can intercept HTTP requests after {@link HttpMessageDecoder} * converts {@link ChannelBuffer}s into HTTP requests. */ -public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler { +public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler + implements LifeCycleAwareChannelHandler { private DecoderEmbedder decoder; @@ -183,4 +185,20 @@ public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler { decoder = null; return result; } + + public void beforeAdd(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void afterAdd(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void beforeRemove(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void afterRemove(ChannelHandlerContext ctx) throws Exception { + finishDecode(); + } } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpContentEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpContentEncoder.java index 90ef2cc06e..184ff6b0d8 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpContentEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpContentEncoder.java @@ -23,6 +23,7 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; +import org.jboss.netty.channel.LifeCycleAwareChannelHandler; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.embedder.EncoderEmbedder; @@ -48,7 +49,8 @@ import org.jboss.netty.handler.codec.embedder.EncoderEmbedder; * so that this handler can intercept HTTP responses before {@link HttpMessageEncoder} * converts them into {@link ChannelBuffer}s. */ -public abstract class HttpContentEncoder extends SimpleChannelHandler { +public abstract class HttpContentEncoder extends SimpleChannelHandler + implements LifeCycleAwareChannelHandler { private final Queue acceptEncodingQueue = new ConcurrentLinkedQueue(); private volatile EncoderEmbedder encoder; @@ -215,4 +217,20 @@ public abstract class HttpContentEncoder extends SimpleChannelHandler { encoder = null; return result; } + + public void beforeAdd(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void afterAdd(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void beforeRemove(ChannelHandlerContext ctx) throws Exception { + // NOOP + } + + public void afterRemove(ChannelHandlerContext ctx) throws Exception { + finishEncode(); + } }