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 committed by GitHub
parent 6cd193e83f
commit 987a68eb02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -989,9 +989,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) {
@ -1014,6 +1013,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();
@ -1033,9 +1034,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) {
@ -1062,6 +1062,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();