Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce2016-08-26 02:31:08 +0000
committerGerrit Code Review @ Eclipse.org2016-08-26 02:31:11 +0000
commitc29363046dae6eb7d469cd86de0ba32c2ea9eef5 (patch)
treee587c53c1cd4c795e33d80f0e4cddc1c9028ac28
parent1227165e27c589a5002840b5fd88f0bfc8a6433b (diff)
parent20d3f83f27946f9654c48f096b2f671f7d5e3662 (diff)
downloadjgit-c29363046dae6eb7d469cd86de0ba32c2ea9eef5.tar.gz
jgit-c29363046dae6eb7d469cd86de0ba32c2ea9eef5.tar.xz
jgit-c29363046dae6eb7d469cd86de0ba32c2ea9eef5.zip
Merge "Fix HttpClientConnection leaking temporary buffer files"
-rw-r--r--org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java30
-rw-r--r--org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/TemporaryBufferEntity.java15
2 files changed, 33 insertions, 12 deletions
diff --git a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
index a0eeef89fc..2d9d17a890 100644
--- a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
+++ b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
@@ -226,17 +226,25 @@ public class HttpClientConnection implements HttpConnection {
}
private void execute() throws IOException, ClientProtocolException {
- if (resp == null)
- if (entity != null) {
- if (req instanceof HttpEntityEnclosingRequest) {
- HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
- eReq.setEntity(entity);
- }
- resp = getClient().execute(req);
- entity.getBuffer().close();
- entity = null;
- } else
- resp = getClient().execute(req);
+ if (resp != null) {
+ return;
+ }
+
+ if (entity == null) {
+ resp = getClient().execute(req);
+ return;
+ }
+
+ try {
+ if (req instanceof HttpEntityEnclosingRequest) {
+ HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
+ eReq.setEntity(entity);
+ }
+ resp = getClient().execute(req);
+ } finally {
+ entity.close();
+ entity = null;
+ }
}
public Map<String, List<String>> getHeaderFields() {
diff --git a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/TemporaryBufferEntity.java b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/TemporaryBufferEntity.java
index 1ff168e237..377e5ca572 100644
--- a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/TemporaryBufferEntity.java
+++ b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/TemporaryBufferEntity.java
@@ -55,7 +55,8 @@ import org.eclipse.jgit.util.TemporaryBuffer;
*
* @since 3.3
*/
-public class TemporaryBufferEntity extends AbstractHttpEntity {
+public class TemporaryBufferEntity extends AbstractHttpEntity
+ implements AutoCloseable {
private TemporaryBuffer buffer;
private Integer contentLength;
@@ -106,4 +107,16 @@ public class TemporaryBufferEntity extends AbstractHttpEntity {
public void setContentLength(int contentLength) {
this.contentLength = new Integer(contentLength);
}
+
+ /**
+ * Close destroys the associated buffer used to buffer the entity
+ *
+ * @since 4.5
+ */
+ @Override
+ public void close() {
+ if (buffer != null) {
+ buffer.destroy();
+ }
+ }
}

Back to the top