From d85757a008fee55069daf367a0bb70774e95bbc6 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 22 Apr 2013 22:18:10 +0900 Subject: [PATCH] Fix memory leak in DefaultChannelHandlerContext .. where freeInbound() and freeOutbound() are not called for all contexts - Fixes #1298 --- .../channel/DefaultChannelHandlerContext.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index 5b2e3f2683..d18cbab6b6 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -1467,15 +1467,14 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements private void invokeFreeInboundBuffer0() { ChannelHandler handler = handler(); - if (handler instanceof ChannelInboundHandler) { - ChannelInboundHandler h = (ChannelInboundHandler) handler; - try { - h.freeInboundBuffer(this); - } catch (Throwable t) { - notifyHandlerException(t); - } finally { - freeInbound(); + try { + if (handler instanceof ChannelInboundHandler) { + ((ChannelInboundHandler) handler).freeInboundBuffer(this); } + } catch (Throwable t) { + notifyHandlerException(t); + } finally { + freeInbound(); } if (next != null) { @@ -1519,15 +1518,14 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements private void invokeFreeOutboundBuffer0() { ChannelHandler handler = handler(); - if (handler instanceof ChannelOutboundHandler) { - ChannelOutboundHandler h = (ChannelOutboundHandler) handler; - try { - h.freeOutboundBuffer(this); - } catch (Throwable t) { - notifyHandlerException(t); - } finally { - freeOutbound(); + try { + if (handler instanceof ChannelOutboundHandler) { + ((ChannelOutboundHandler) handler).freeOutboundBuffer(this); } + } catch (Throwable t) { + notifyHandlerException(t); + } finally { + freeOutbound(); } if (prev != null) {