From 30db808d0f3c42f58c605f9af6903244d4ee7649 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Tue, 7 Oct 2014 00:11:08 +0200 Subject: [PATCH] Fix the leak in the WebSocketClientProtocolHandshakeHandler Motivation: The WebSocketClientProtocolHandshakeHandler never releases the received handshake response. Modification: Release the message in a finally block. Result: No more leak --- ...bSocketClientProtocolHandshakeHandler.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java index f9b8b40c31..bc83251081 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java @@ -51,13 +51,18 @@ class WebSocketClientProtocolHandshakeHandler extends ChannelHandlerAdapter { return; } - if (!handshaker.isHandshakeComplete()) { - handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) msg); - ctx.fireUserEventTriggered( - WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); - ctx.pipeline().remove(this); - return; + FullHttpResponse response = (FullHttpResponse) msg; + try { + if (!handshaker.isHandshakeComplete()) { + handshaker.finishHandshake(ctx.channel(), response); + ctx.fireUserEventTriggered( + WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); + ctx.pipeline().remove(this); + return; + } + throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet"); + } finally { + response.release(); } - throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet"); } }