Fix buffer leaks in Bzip2Decoder(Test)
If decompression fails, the buffer that contains the decompressed data is not released. Bzip2DecoderTest.testStreamCrcError() also does not release the partial output Bzip2Decoder produces.
This commit is contained in:
parent
c0462c0c3b
commit
5f889d92a1
|
@ -276,17 +276,26 @@ public class Bzip2Decoder extends ByteToMessageDecoder {
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int blockLength = blockDecompressor.blockLength();
|
|
||||||
ByteBuf uncompressed = ctx.alloc().buffer(blockLength);
|
final int blockLength = blockDecompressor.blockLength();
|
||||||
int uncByte;
|
final ByteBuf uncompressed = ctx.alloc().buffer(blockLength);
|
||||||
while ((uncByte = blockDecompressor.read()) >= 0) {
|
boolean success = false;
|
||||||
uncompressed.writeByte(uncByte);
|
try {
|
||||||
|
int uncByte;
|
||||||
|
while ((uncByte = blockDecompressor.read()) >= 0) {
|
||||||
|
uncompressed.writeByte(uncByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentBlockCRC = blockDecompressor.checkCRC();
|
||||||
|
streamCRC = (streamCRC << 1 | streamCRC >>> 31) ^ currentBlockCRC;
|
||||||
|
|
||||||
|
out.add(uncompressed);
|
||||||
|
success = true;
|
||||||
|
} finally {
|
||||||
|
if (!success) {
|
||||||
|
uncompressed.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentBlockCRC = blockDecompressor.checkCRC();
|
|
||||||
streamCRC = (streamCRC << 1 | streamCRC >>> 31) ^ currentBlockCRC;
|
|
||||||
|
|
||||||
out.add(uncompressed);
|
|
||||||
currentState = State.INIT_BLOCK;
|
currentState = State.INIT_BLOCK;
|
||||||
break;
|
break;
|
||||||
case EOF:
|
case EOF:
|
||||||
|
|
|
@ -119,7 +119,18 @@ public class Bzip2DecoderTest {
|
||||||
0x4E, 0x14, 0x24, 0x1D, (byte) 0xDD, (byte) 0xF2, (byte) 0xB0, 0x00 };
|
0x4E, 0x14, 0x24, 0x1D, (byte) 0xDD, (byte) 0xF2, (byte) 0xB0, 0x00 };
|
||||||
|
|
||||||
ByteBuf in = Unpooled.wrappedBuffer(data);
|
ByteBuf in = Unpooled.wrappedBuffer(data);
|
||||||
channel.writeInbound(in);
|
try {
|
||||||
|
channel.writeInbound(in);
|
||||||
|
} finally {
|
||||||
|
for (;;) {
|
||||||
|
ByteBuf inflated = channel.readInbound();
|
||||||
|
if (inflated == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
inflated.release();
|
||||||
|
}
|
||||||
|
channel.finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user