Преглед изворни кода

fix(azure): close response body and validate HTTP status codes (#3919)

Signed-off-by: Kush Agarwal <agrawalkush783@gmail.com>
Kush Agarwal пре 1 месец
родитељ
комит
187f9a4fef
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      pkg/cloud/azure/provider.go

+ 2 - 1
pkg/cloud/azure/provider.go

@@ -317,8 +317,9 @@ func getRetailPrice(region string, skuName string, currencyCode string, spot boo
 	if err != nil {
 		return "", fmt.Errorf("failed to fetch retail price with URL \"%s\": %w", pricingURL, err)
 	}
+	defer resp.Body.Close()
 
-	if resp.StatusCode < 200 && resp.StatusCode > 299 {
+	if resp.StatusCode < 200 || resp.StatusCode > 299 {
 		return "", fmt.Errorf("retail price responded with error status code %d", resp.StatusCode)
 	}