Fix memory leak in HttpPostMultipartRequestDecoder (#10227)

Motivation:

We need to release all ByteBufs that we allocate to prevent leaks. We missed to release the ByteBufs that are used to aggregate in two cases

Modifications:

Add release() calls

Result:

No more memory leak in HttpPostMultipartRequestDecoder
This commit is contained in:
Norman Maurer 2020-04-29 08:23:41 +02:00
parent 7b56aabec6
commit 65a967c772

View File

@ -973,9 +973,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
*/
private static String readLineStandard(ByteBuf undecodedChunk, Charset charset) {
int readerIndex = undecodedChunk.readerIndex();
ByteBuf line = buffer(64);
try {
ByteBuf line = buffer(64);
while (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.CR) {
@ -998,6 +997,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
} catch (IndexOutOfBoundsException e) {
undecodedChunk.readerIndex(readerIndex);
throw new NotEnoughDataDecoderException(e);
} finally {
line.release();
}
undecodedChunk.readerIndex(readerIndex);
throw new NotEnoughDataDecoderException();
@ -1017,9 +1018,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
}
SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk);
int readerIndex = undecodedChunk.readerIndex();
ByteBuf line = buffer(64);
try {
ByteBuf line = buffer(64);
while (sao.pos < sao.limit) {
byte nextByte = sao.bytes[sao.pos++];
if (nextByte == HttpConstants.CR) {
@ -1046,6 +1046,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
} catch (IndexOutOfBoundsException e) {
undecodedChunk.readerIndex(readerIndex);
throw new NotEnoughDataDecoderException(e);
} finally {
line.release();
}
undecodedChunk.readerIndex(readerIndex);
throw new NotEnoughDataDecoderException();