From 7cb202bc36e004ec7c0b1e33aaac083e5d767aec Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 3 Nov 2017 01:22:19 +0100 Subject: [PATCH] Fixed byte buffer leak in Netty4 request handler If creating the REST request throws an exception (for example, because of invalid headers), we leak the request due to failure to release the buffer (which would otherwise happen after replying on the channel). This commit addresses this leak by handling the failure case. Relates #27222 --- .../http/netty4/Netty4HttpRequestHandler.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestHandler.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestHandler.java index b31c412920aa1..6da0f5433bae6 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestHandler.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestHandler.java @@ -64,7 +64,15 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except Unpooled.copiedBuffer(request.content()), request.headers(), request.trailingHeaders()); - final Netty4HttpRequest httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel()); + final Netty4HttpRequest httpRequest; + try { + httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel()); + } catch (Exception ex) { + if (pipelinedRequest != null) { + pipelinedRequest.release(); + } + throw ex; + } final Netty4HttpChannel channel = new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext);