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
491b1f428b
commit
95527eec91
@ -148,6 +148,7 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD
|
||||
this.request = checkNotNull(request, "request");
|
||||
this.charset = checkNotNull(charset, "charset");
|
||||
this.factory = checkNotNull(factory, "factory");
|
||||
try {
|
||||
if (request instanceof HttpContent) {
|
||||
// Offer automatically if the given request is als type of HttpContent
|
||||
// See #1089
|
||||
@ -156,6 +157,10 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD
|
||||
undecodedChunk = buffer();
|
||||
parseBody();
|
||||
}
|
||||
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
|
||||
destroy();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDestroyed() {
|
||||
|
@ -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