From e3ec124ccd88e9f9f7461315ee659a222f9828fd Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 11 Jun 2013 08:53:14 +0200 Subject: [PATCH] Make sure WebSocketFrameAggregator and HttpObjectAggregator don't leak ByteBufs --- .../codec/http/HttpObjectAggregator.java | 22 +++++++++++++++++++ .../websocketx/WebSocketFrameAggregator.java | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java index 151736a847..54d3f318d1 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java @@ -210,8 +210,30 @@ public class HttpObjectAggregator extends MessageToMessageDecoder { } } + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + super.channelInactive(ctx); + + // release current message if it is not null as it may be a left-over + if (currentMessage != null) { + currentMessage.release(); + currentMessage = null; + } + } + @Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { this.ctx = ctx; } + + @Override + public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { + super.handlerRemoved(ctx); + // release current message if it is not null as it may be a left-over as there is not much more we can do in + // this case + if (currentMessage != null) { + currentMessage.release(); + currentMessage = null; + } + } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregator.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregator.java index 739ff18e2f..10eb9e31f2 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregator.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregator.java @@ -97,4 +97,26 @@ public class WebSocketFrameAggregator extends MessageToMessageDecoder