From 4a92ed1e0c411b9ed1fb62f202ebd7286f77c38c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 13 May 2014 06:50:38 +0200 Subject: [PATCH] Fix buffer leaks in HTTP2 --- .../codec/http2/AbstractHttp2ConnectionHandler.java | 2 +- .../io/netty/handler/codec/http2/Http2CodecUtil.java | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java index 81f9bbf5e4..f8c86f5d01 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java @@ -108,7 +108,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode this.outboundFlow = outboundFlow; // Set the expected client preface string. Only servers should receive this. - this.clientPrefaceString = connection.isServer()? connectionPrefaceBuf() : null; + clientPrefaceString = connection.isServer()? connectionPrefaceBuf() : null; } @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2CodecUtil.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2CodecUtil.java index b40931878c..b33bbaf341 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2CodecUtil.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2CodecUtil.java @@ -27,10 +27,8 @@ import io.netty.channel.ChannelPromise; * Constants and utility method used for encoding/decoding HTTP2 frames. */ public final class Http2CodecUtil { - private static final ByteBuf CONNECTION_PREFACE_BUF = Unpooled.unmodifiableBuffer(Unpooled - .copiedBuffer("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", UTF_8)); - private static final ByteBuf EMPTY_PING_BUF = Unpooled.unmodifiableBuffer(Unpooled - .copiedBuffer(new byte[8])); + private static final byte[] CONNECTION_PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".getBytes(UTF_8); + private static final byte[] EMPTY_PING = new byte[8]; public static final int CONNECTION_STREAM_ID = 0; public static final int MAX_FRAME_PAYLOAD_LENGTH = 16383; @@ -63,7 +61,7 @@ public final class Http2CodecUtil { public static ByteBuf connectionPrefaceBuf() { // Return a duplicate so that modifications to the reader index will not affect the original // buffer. - return CONNECTION_PREFACE_BUF.duplicate().retain(); + return Unpooled.wrappedBuffer(CONNECTION_PREFACE); } /** @@ -72,7 +70,7 @@ public final class Http2CodecUtil { public static ByteBuf emptyPingBuf() { // Return a duplicate so that modifications to the reader index will not affect the original // buffer. - return EMPTY_PING_BUF.duplicate().retain(); + return Unpooled.wrappedBuffer(EMPTY_PING); } /**