Skip to content

Commit 2f9ad15

Browse files
committed
Use the source frame's allocator instead of the unpooled allocator
1 parent ae6aea7 commit 2f9ad15

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoder.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package io.netty.handler.codec.spdy;
1717

1818
import io.netty.buffer.ByteBuf;
19-
import io.netty.buffer.Unpooled;
19+
import io.netty.buffer.ByteBufAllocator;
2020

2121
import java.util.zip.DataFormatException;
2222
import java.util.zip.Inflater;
@@ -41,7 +41,7 @@ void decode(ByteBuf encoded, SpdyHeadersFrame frame) throws Exception {
4141

4242
int numBytes;
4343
do {
44-
numBytes = decompress(frame);
44+
numBytes = decompress(encoded.alloc(), frame);
4545
} while (numBytes > 0);
4646

4747
if (decompressor.getRemaining() != 0) {
@@ -65,8 +65,8 @@ private int setInput(ByteBuf compressed) {
6565
return len;
6666
}
6767

68-
private int decompress(SpdyHeadersFrame frame) throws Exception {
69-
ensureBuffer();
68+
private int decompress(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception {
69+
ensureBuffer(alloc);
7070
byte[] out = decompressed.array();
7171
int off = decompressed.arrayOffset() + decompressed.writerIndex();
7272
try {
@@ -87,23 +87,30 @@ private int decompress(SpdyHeadersFrame frame) throws Exception {
8787
}
8888
}
8989

90-
private void ensureBuffer() {
90+
private void ensureBuffer(ByteBufAllocator alloc) {
9191
if (decompressed == null) {
92-
decompressed = Unpooled.buffer(DEFAULT_BUFFER_CAPACITY);
92+
decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
9393
}
9494
decompressed.ensureWritable(1);
9595
}
9696

9797
@Override
9898
void reset() {
99-
decompressed = null;
99+
releaseBuffer();
100100
super.reset();
101101
}
102102

103103
@Override
104104
public void end() {
105-
decompressed = null;
105+
releaseBuffer();
106106
decompressor.end();
107107
super.end();
108108
}
109+
110+
private void releaseBuffer() {
111+
if (decompressed != null) {
112+
decompressed.release();
113+
decompressed = null;
114+
}
115+
}
109116
}

0 commit comments

Comments
 (0)