[#539] Fix potential direct memory leak in HttpContentEn/Decoder
This commit is contained in:
parent
ebbcfbc185
commit
513fc4f78b
@ -62,7 +62,8 @@ public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler {
|
||||
} else if (msg instanceof HttpMessage) {
|
||||
HttpMessage m = (HttpMessage) msg;
|
||||
|
||||
decoder = null;
|
||||
// Clean-up the previous encoder if not cleaned up correctly.
|
||||
finishDecode();
|
||||
|
||||
// Determine the content encoding.
|
||||
String contentEncoding = m.getHeader(HttpHeaders.Names.CONTENT_ENCODING);
|
||||
@ -160,6 +161,10 @@ public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler {
|
||||
}
|
||||
|
||||
private ChannelBuffer finishDecode() {
|
||||
if (decoder == null) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
ChannelBuffer result;
|
||||
if (decoder.finish()) {
|
||||
result = ChannelBuffers.wrappedBuffer(decoder.pollAll(new ChannelBuffer[decoder.size()]));
|
||||
|
@ -90,7 +90,8 @@ public abstract class HttpContentEncoder extends SimpleChannelHandler {
|
||||
} else if (msg instanceof HttpMessage) {
|
||||
HttpMessage m = (HttpMessage) msg;
|
||||
|
||||
encoder = null;
|
||||
// Clean-up the previous encoder if not cleaned up correctly.
|
||||
finishEncode();
|
||||
|
||||
String acceptEncoding = acceptEncodingQueue.poll();
|
||||
if (acceptEncoding == null) {
|
||||
@ -192,6 +193,10 @@ public abstract class HttpContentEncoder extends SimpleChannelHandler {
|
||||
}
|
||||
|
||||
private ChannelBuffer finishEncode() {
|
||||
if (encoder == null) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
ChannelBuffer result;
|
||||
if (encoder.finish()) {
|
||||
result = ChannelBuffers.wrappedBuffer(encoder.pollAll(new ChannelBuffer[encoder.size()]));
|
||||
|
Loading…
x
Reference in New Issue
Block a user