From 1040a5c779c9d224286518e59643ebcb8b9e6353 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 21 Mar 2012 15:56:11 -0700 Subject: [PATCH] Close streams on error paths --- .../http/internal/BaseHttpCommandExecutorService.java | 1 + .../http/internal/JavaUrlHttpCommandExecutorService.java | 5 +---- .../test/java/org/jclouds/rest/BaseRestClientExpectTest.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java index 7a60a37219..ffaf49e1a1 100644 --- a/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java @@ -156,6 +156,7 @@ public abstract class BaseHttpCommandExecutorService implements HttpCommandEx utils.logResponse(headerLog, response, "<<"); if (response.getPayload() != null && wire.enabled()) wire.input(response); + nativeRequest = null; // response took ownership of streams int statusCode = response.getStatusCode(); if (statusCode >= 300) { if (shouldContinue(response)) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index b6791fee98..21108564c5 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -255,12 +255,9 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe } - /** - * Only disconnect if there is no content, as disconnecting will throw away unconsumed content. - */ @Override protected void cleanup(HttpURLConnection connection) { - if (connection != null && connection.getContentLength() == 0) + if (connection != null) connection.disconnect(); } diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java index 9d8ced9f19..f46002a17f 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java +++ b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java @@ -201,7 +201,7 @@ public abstract class BaseRestClientExpectTest { @Override public void cleanup(HttpRequest nativeResponse) { - if (nativeResponse.getPayload() != null) + if (nativeResponse != null && nativeResponse.getPayload() != null) nativeResponse.getPayload().release(); }