From 2b769c6daf075183d82f96b78960cfaf6fe2d347 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 6 Feb 2014 21:23:10 -0800 Subject: [PATCH] Fix resource leaks in WebSocketServerProtocolHandler - Related: #1975 --- .../http/websocketx/WebSocketServerProtocolHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java index c21694b7f1..36a4248c0a 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java @@ -94,8 +94,12 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler { protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List out) throws Exception { if (frame instanceof CloseWebSocketFrame) { WebSocketServerHandshaker handshaker = getHandshaker(ctx); - frame.retain(); - handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame); + if (handshaker != null) { + frame.retain(); + handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame); + } else { + ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); + } return; } super.decode(ctx, frame, out);