HttpPostStandardRequestDecoder leaks memory when constructor throws ErrorDataDecoderException. (#9517)
Motivation: Currently when HttpPostStandardRequestDecoder throws a ErrorDataDecoderException during construction we leak memory. We need to ensure all is released correctly. Modifications: - Call destroy() if parseBody() throws and rethrow the ErrorDataDecoderException - Add unit test Result: Fixes https://github.com/netty/netty/issues/9513.
This commit is contained in:
parent
88e247ee45
commit
64eb392d70
@ -149,13 +149,18 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD
|
||||
this.request = requireNonNull(request, "request");
|
||||
this.charset = requireNonNull(charset, "charset");
|
||||
this.factory = requireNonNull(factory, "factory");
|
||||
if (request instanceof HttpContent) {
|
||||
// Offer automatically if the given request is als type of HttpContent
|
||||
// See #1089
|
||||
offer((HttpContent) request);
|
||||
} else {
|
||||
undecodedChunk = buffer();
|
||||
parseBody();
|
||||
try {
|
||||
if (request instanceof HttpContent) {
|
||||
// Offer automatically if the given request is als type of HttpContent
|
||||
// See #1089
|
||||
offer((HttpContent) request);
|
||||
} else {
|
||||
undecodedChunk = buffer();
|
||||
parseBody();
|
||||
}
|
||||
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
|
||||
destroy();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -723,4 +723,15 @@ public class HttpPostRequestDecoderTest {
|
||||
decoder.destroy();
|
||||
assertEquals(1, req.refCnt());
|
||||
}
|
||||
|
||||
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
|
||||
public void testNotLeak() {
|
||||
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
|
||||
Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII));
|
||||
try {
|
||||
new HttpPostStandardRequestDecoder(request);
|
||||
} finally {
|
||||
assertTrue(request.release());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user