From 407111a79630b9f79a377c1ee5ef96fc09ddbe46 Mon Sep 17 00:00:00 2001
From: Sergiu Prodan
Date: Thu, 6 Oct 2016 17:10:37 +0300
Subject: [PATCH] Issue #295 Ensure Jetty Client use of Inflater calls .end()
to avoid memory leak
Signed-off-by: Sergiu Prodan
---
.../org/eclipse/jetty/client/GZIPContentDecoder.java | 9 ++++++++-
.../java/org/eclipse/jetty/client/HttpReceiver.java | 11 +++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java b/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java
index 8bae3b8a993..2ee10aa9a48 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java
@@ -25,11 +25,12 @@ import java.util.zip.Inflater;
import java.util.zip.ZipException;
import org.eclipse.jetty.util.BufferUtil;
+import org.eclipse.jetty.util.component.Destroyable;
/**
* {@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 byte[] bytes;
@@ -322,6 +323,12 @@ public class GZIPContentDecoder implements ContentDecoder
flags = 0;
}
+ @Override
+ public void destroy()
+ {
+ inflater.end();
+ }
+
protected boolean isFinished()
{
return state == State.INITIAL;
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java
index e5bbdee4a79..aa7956c180c 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java
@@ -37,6 +37,7 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
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.Logger;
@@ -469,6 +470,7 @@ public abstract class HttpReceiver
*/
protected void reset()
{
+ destroyDecoder(decoder);
decoder = null;
}
@@ -481,9 +483,18 @@ public abstract class HttpReceiver
*/
protected void dispose()
{
+ destroyDecoder(decoder);
decoder = null;
}
+ private static void destroyDecoder(ContentDecoder decoder)
+ {
+ if (decoder instanceof Destroyable)
+ {
+ ((Destroyable)decoder).destroy();
+ }
+ }
+
public boolean abort(HttpExchange exchange, Throwable failure)
{
// Update the state to avoid more response processing.