Skip to content

Commit 8f087ee

Browse files
iamanmolmHarness
authored andcommitted
[fix]: [CCM-32390]: Fix potential memory leak in cloud-info (#43)
* aeb36b [fix]: [CCM-32390]: Fix potential memory leak in cloud-info
1 parent 6ed7296 commit 8f087ee

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

internal/cloudinfo/providers/azure/cloudinfo.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ func (a *AzureInfoer) getPricingWithRetailPricesAPI() (map[string]map[string]typ
240240
totalOnDemandSet := 0
241241
totalSpotSet := 0
242242

243+
client := &http.Client{}
243244
url := baseURL
244245
for url != "" {
245-
client := &http.Client{}
246246
req, _ := http.NewRequest("GET", url, nil)
247247
req.Header.Set("User-Agent", "go-client")
248248

@@ -255,10 +255,10 @@ func (a *AzureInfoer) getPricingWithRetailPricesAPI() (map[string]map[string]typ
255255
})
256256
return allPrices, fmt.Errorf("failed to call retail API: %w", err)
257257
}
258-
defer resp.Body.Close()
259258

260259
if resp.StatusCode != http.StatusOK {
261260
body, _ := io.ReadAll(resp.Body)
261+
resp.Body.Close()
262262
a.log.Error("RetailPricesAPI: non-200 status", map[string]interface{}{
263263
"statusCode": resp.StatusCode,
264264
"page": pageCount,
@@ -269,6 +269,7 @@ func (a *AzureInfoer) getPricingWithRetailPricesAPI() (map[string]map[string]typ
269269
}
270270

271271
body, err := io.ReadAll(resp.Body)
272+
resp.Body.Close()
272273
if err != nil {
273274
return allPrices, fmt.Errorf("error while getting body %w", err)
274275
}
@@ -584,8 +585,8 @@ func (a *AzureInfoer) GetVirtualMachines(region string) ([]types.VMInfo, error)
584585
skusResultPage, err := a.skusClient.List(context.Background())
585586
if err != nil {
586587
logger.Error("GetVirtualMachines: SKU API List() failed", map[string]interface{}{
587-
"error": err.Error(),
588-
"elapsed": time.Since(startTime).String(),
588+
"error": err.Error(),
589+
"elapsed": time.Since(startTime).String(),
589590
})
590591
return nil, err
591592
}
@@ -698,9 +699,9 @@ func (a *AzureInfoer) GetVirtualMachines(region string) ([]types.VMInfo, error)
698699
}
699700

700701
logger.Info("GetVirtualMachines: page VMs found", map[string]interface{}{
701-
"page": totalPages,
702-
"vmsInRegion": pageVMsInRegion,
703-
"totalVMsSoFar": len(virtualMachines),
702+
"page": totalPages,
703+
"vmsInRegion": pageVMsInRegion,
704+
"totalVMsSoFar": len(virtualMachines),
704705
})
705706
}
706707

0 commit comments

Comments
 (0)