From 16b05def59bf321ce5d6354e852ff198ccfcca27 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 6 Dec 2012 19:36:53 +0100 Subject: [PATCH] Fix possible NPE which accour if the inbound/outbound buffer was not lazy allocated yet --- .../channel/DefaultChannelHandlerContext.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index cf5cff9185..466de34188 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -160,10 +160,14 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements if (ctx.handler instanceof ChannelInboundHandler) { ChannelInboundHandler h = (ChannelInboundHandler) ctx.handler; try { - if (ctx.inByteBuf != null) { - h.freeInboundBuffer(ctx, ctx.inByteBuf); + if (ctx.hasInboundByteBuffer()) { + if (ctx.inByteBuf != null) { + h.freeInboundBuffer(ctx, ctx.inByteBuf); + } } else { - h.freeInboundBuffer(ctx, ctx.inMsgBuf); + if (ctx.inMsgBuf != null) { + h.freeInboundBuffer(ctx, ctx.inMsgBuf); + } } } catch (Throwable t) { pipeline.notifyHandlerException(t); @@ -186,10 +190,14 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements if (ctx.handler instanceof ChannelOutboundHandler) { ChannelOutboundHandler h = (ChannelOutboundHandler) ctx.handler; try { - if (ctx.outByteBuf != null) { - h.freeOutboundBuffer(ctx, ctx.outByteBuf); + if (ctx.hasOutboundByteBuffer()) { + if (ctx.outByteBuf != null) { + h.freeOutboundBuffer(ctx, ctx.outByteBuf); + } } else { - h.freeOutboundBuffer(ctx, ctx.outMsgBuf); + if (ctx.outMsgBuf != null) { + h.freeOutboundBuffer(ctx, ctx.outMsgBuf); + } } } catch (Throwable t) { pipeline.notifyHandlerException(t);