diff --git a/api/cloudcontroller/cloud_controller_connection.go b/api/cloudcontroller/cloud_controller_connection.go index 525f49a5f1f..c82280dce69 100644 --- a/api/cloudcontroller/cloud_controller_connection.go +++ b/api/cloudcontroller/cloud_controller_connection.go @@ -64,7 +64,6 @@ func (*CloudControllerConnection) handleStatusCodes(response *http.Response, pas passedResponse.RawResponse = []byte("{}") } else { rawBytes, err := ioutil.ReadAll(response.Body) - defer response.Body.Close() if err != nil { return err } @@ -105,6 +104,7 @@ func (*CloudControllerConnection) handleWarnings(response *http.Response) ([]str func (connection *CloudControllerConnection) populateResponse(response *http.Response, passedResponse *Response) error { passedResponse.HTTPResponse = response + defer response.Body.Close() warnings, err := connection.handleWarnings(response) if err != nil {