Fix a leak in WebSocketServerProtocolHandshakeHandler

- Related: #1975
This commit is contained in:
Trustin Lee 2014-02-06 20:57:55 -08:00
parent 50f8cc98d1
commit c01f08d306

View File

@ -41,7 +41,7 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {
private final String subprotocols; private final String subprotocols;
private final boolean allowExtensions; private final boolean allowExtensions;
public WebSocketServerProtocolHandshakeHandler(String websocketPath, String subprotocols, WebSocketServerProtocolHandshakeHandler(String websocketPath, String subprotocols,
boolean allowExtensions) { boolean allowExtensions) {
this.websocketPath = websocketPath; this.websocketPath = websocketPath;
this.subprotocols = subprotocols; this.subprotocols = subprotocols;
@ -51,6 +51,7 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {
@Override @Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
FullHttpRequest req = (FullHttpRequest) msg; FullHttpRequest req = (FullHttpRequest) msg;
try {
if (req.getMethod() != GET) { if (req.getMethod() != GET) {
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN)); sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
return; return;
@ -78,6 +79,9 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {
ctx.pipeline().replace(this, "WS403Responder", ctx.pipeline().replace(this, "WS403Responder",
WebSocketServerProtocolHandler.forbiddenHttpRequestResponder()); WebSocketServerProtocolHandler.forbiddenHttpRequestResponder());
} }
} finally {
req.release();
}
} }
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {