* Issue #295 Ensure Jetty Client use of Inflater calls .end() to avoid memory leak Signed-off-by: Sergiu Prodan <p.sergiu92@gmail.com>
This commit is contained in:
parent
fc447fe2a3
commit
f8b2979a8f
|
@ -25,11 +25,12 @@ import java.util.zip.Inflater;
|
||||||
import java.util.zip.ZipException;
|
import java.util.zip.ZipException;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
|
import org.eclipse.jetty.util.component.Destroyable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ContentDecoder} for the "gzip" encoding.
|
* {@link ContentDecoder} for the "gzip" encoding.
|
||||||
*/
|
*/
|
||||||
public class GZIPContentDecoder implements ContentDecoder
|
public class GZIPContentDecoder implements ContentDecoder, Destroyable
|
||||||
{
|
{
|
||||||
private final Inflater inflater = new Inflater(true);
|
private final Inflater inflater = new Inflater(true);
|
||||||
private final byte[] bytes;
|
private final byte[] bytes;
|
||||||
|
@ -322,6 +323,12 @@ public class GZIPContentDecoder implements ContentDecoder
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy()
|
||||||
|
{
|
||||||
|
inflater.end();
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isFinished()
|
protected boolean isFinished()
|
||||||
{
|
{
|
||||||
return state == State.INITIAL;
|
return state == State.INITIAL;
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.util.Callback;
|
import org.eclipse.jetty.util.Callback;
|
||||||
import org.eclipse.jetty.util.CountingCallback;
|
import org.eclipse.jetty.util.CountingCallback;
|
||||||
|
import org.eclipse.jetty.util.component.Destroyable;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
@ -465,6 +466,7 @@ public abstract class HttpReceiver
|
||||||
*/
|
*/
|
||||||
protected void reset()
|
protected void reset()
|
||||||
{
|
{
|
||||||
|
destroyDecoder(decoder);
|
||||||
decoder = null;
|
decoder = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,9 +479,18 @@ public abstract class HttpReceiver
|
||||||
*/
|
*/
|
||||||
protected void dispose()
|
protected void dispose()
|
||||||
{
|
{
|
||||||
|
destroyDecoder(decoder);
|
||||||
decoder = null;
|
decoder = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void destroyDecoder(ContentDecoder decoder)
|
||||||
|
{
|
||||||
|
if (decoder instanceof Destroyable)
|
||||||
|
{
|
||||||
|
((Destroyable)decoder).destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean abort(HttpExchange exchange, Throwable failure)
|
public boolean abort(HttpExchange exchange, Throwable failure)
|
||||||
{
|
{
|
||||||
// Update the state to avoid more response processing.
|
// Update the state to avoid more response processing.
|
||||||
|
|
Loading…
Reference in New Issue