Fix memory leak in DefaultChannelHandlerContext

.. where freeInbound() and freeOutbound() are not called for all contexts

- Fixes #1298
This commit is contained in:
Trustin Lee 2013-04-22 22:18:10 +09:00
parent e80fb65c36
commit d85757a008

View File

@ -1467,16 +1467,15 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
private void invokeFreeInboundBuffer0() { private void invokeFreeInboundBuffer0() {
ChannelHandler handler = handler(); ChannelHandler handler = handler();
if (handler instanceof ChannelInboundHandler) {
ChannelInboundHandler h = (ChannelInboundHandler) handler;
try { try {
h.freeInboundBuffer(this); if (handler instanceof ChannelInboundHandler) {
((ChannelInboundHandler) handler).freeInboundBuffer(this);
}
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(t); notifyHandlerException(t);
} finally { } finally {
freeInbound(); freeInbound();
} }
}
if (next != null) { if (next != null) {
DefaultChannelHandlerContext nextCtx = findContextInbound(); DefaultChannelHandlerContext nextCtx = findContextInbound();
@ -1519,16 +1518,15 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
private void invokeFreeOutboundBuffer0() { private void invokeFreeOutboundBuffer0() {
ChannelHandler handler = handler(); ChannelHandler handler = handler();
if (handler instanceof ChannelOutboundHandler) {
ChannelOutboundHandler h = (ChannelOutboundHandler) handler;
try { try {
h.freeOutboundBuffer(this); if (handler instanceof ChannelOutboundHandler) {
((ChannelOutboundHandler) handler).freeOutboundBuffer(this);
}
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(t); notifyHandlerException(t);
} finally { } finally {
freeOutbound(); freeOutbound();
} }
}
if (prev != null) { if (prev != null) {
findContextOutbound().invokeFreeOutboundBuffer(); findContextOutbound().invokeFreeOutboundBuffer();