From 2f9ad15d3f9febe3fd23f97f9b3fda5e5533e9a8 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 14 Jan 2014 14:22:06 +0900 Subject: [PATCH] Use the source frame's allocator instead of the unpooled allocator --- .../spdy/SpdyHeaderBlockZlibDecoder.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoder.java index 4bb1c12a7d..a4df123043 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoder.java @@ -16,7 +16,7 @@ package io.netty.handler.codec.spdy; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; +import io.netty.buffer.ByteBufAllocator; import java.util.zip.DataFormatException; import java.util.zip.Inflater; @@ -41,7 +41,7 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder { int numBytes; do { - numBytes = decompress(frame); + numBytes = decompress(encoded.alloc(), frame); } while (numBytes > 0); if (decompressor.getRemaining() != 0) { @@ -65,8 +65,8 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder { return len; } - private int decompress(SpdyHeadersFrame frame) throws Exception { - ensureBuffer(); + private int decompress(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception { + ensureBuffer(alloc); byte[] out = decompressed.array(); int off = decompressed.arrayOffset() + decompressed.writerIndex(); try { @@ -87,23 +87,30 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder { } } - private void ensureBuffer() { + private void ensureBuffer(ByteBufAllocator alloc) { if (decompressed == null) { - decompressed = Unpooled.buffer(DEFAULT_BUFFER_CAPACITY); + decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY); } decompressed.ensureWritable(1); } @Override void reset() { - decompressed = null; + releaseBuffer(); super.reset(); } @Override public void end() { - decompressed = null; + releaseBuffer(); decompressor.end(); super.end(); } + + private void releaseBuffer() { + if (decompressed != null) { + decompressed.release(); + decompressed = null; + } + } }