From 17a4ae8878e403861f6568f84f20beccb8bc22d1 Mon Sep 17 00:00:00 2001 From: Chitoku Date: Thu, 18 May 2023 23:35:49 +0900 Subject: [PATCH] Ensure response body is always closed in CloudControllerConnection --- api/cloudcontroller/cloud_controller_connection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 {