Ensure uncompressed ByteBuf is released when an exception happens during decoding.
Motivation: We need to ensure the uncompressed ByteBuf is released if an exception happens while calling decode(...). If we miss to do so we leak buffers. Modifications: Correctly release buffer on exception. Result: No more memory leak.
This commit is contained in:
parent
94d7557dea
commit
7db3e01498
@ -166,7 +166,8 @@ public class SnappyFrameDecoder extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
in.skipBytes(4);
|
in.skipBytes(4);
|
||||||
int checksum = in.readIntLE();
|
int checksum = in.readIntLE();
|
||||||
ByteBuf uncompressed = ctx.alloc().buffer(0);
|
ByteBuf uncompressed = ctx.alloc().buffer();
|
||||||
|
try {
|
||||||
if (validateChecksums) {
|
if (validateChecksums) {
|
||||||
int oldWriterIndex = in.writerIndex();
|
int oldWriterIndex = in.writerIndex();
|
||||||
try {
|
try {
|
||||||
@ -180,6 +181,12 @@ public class SnappyFrameDecoder extends ByteToMessageDecoder {
|
|||||||
snappy.decode(in.readSlice(chunkLength - 4), uncompressed);
|
snappy.decode(in.readSlice(chunkLength - 4), uncompressed);
|
||||||
}
|
}
|
||||||
out.add(uncompressed);
|
out.add(uncompressed);
|
||||||
|
uncompressed = null;
|
||||||
|
} finally {
|
||||||
|
if (uncompressed != null) {
|
||||||
|
uncompressed.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
snappy.reset();
|
snappy.reset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user