Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cns/dockerclient/dockerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (dockerClient *DockerClient) NetworkExists(networkName string) error {
return err
}

defer res.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need to Close sockets multiple times, you should give those res different names. Even though they're pointers & should work fine, it will still cause confusion.


// network exists
if res.StatusCode == 200 {
log.Debugf("[Azure CNS] Network with name %v already exists. Docker return code: %v", networkName, res.StatusCode)
Expand Down Expand Up @@ -122,6 +124,9 @@ func (dockerClient *DockerClient) CreateNetwork(networkName string, nicInfo *imd
log.Printf("[Azure CNS] Error received from http Post for docker network create %v", networkName)
return err
}

defer res.Body.Close()

if res.StatusCode != 201 {
var createNetworkResponse DockerErrorResponse
err = json.NewDecoder(res.Body).Decode(&createNetworkResponse)
Expand Down Expand Up @@ -158,6 +163,12 @@ func (dockerClient *DockerClient) DeleteNetwork(networkName string) error {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
log.Printf("[Azure CNS] HTTP Post returned error %v", err.Error())
return err
}

defer res.Body.Close()

// network successfully deleted.
if res.StatusCode == 204 {
Expand Down
4 changes: 4 additions & 0 deletions cns/imdsclient/imdsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (imdsClient *ImdsClient) GetNetworkContainerInfoFromHost(networkContainerID
return nil, err
}

defer jsonResponse.Body.Close()

log.Printf("[Azure CNS] Response received from Azure Host for NetworkManagement/interfaces: %v", jsonResponse.Body)

var response containerVersionJsonResponse
Expand All @@ -51,6 +53,8 @@ func (imdsClient *ImdsClient) GetPrimaryInterfaceInfoFromHost() (*InterfaceInfo,
return nil, err
}

defer resp.Body.Close()

log.Printf("[Azure CNS] Response received from NMAgent for get interface details: %v", resp.Body)

var doc xmlDocument
Expand Down
10 changes: 10 additions & 0 deletions cns/ipamclient/ipamclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (ic *IpamClient) GetAddressSpace() (string, error) {
return "", err
}

defer res.Body.Close()

if res.StatusCode == 200 {
var resp cnmIpam.GetDefaultAddressSpacesResponse
err := json.NewDecoder(res.Body).Decode(&resp)
Expand Down Expand Up @@ -89,6 +91,8 @@ func (ic *IpamClient) GetPoolID(asID, subnet string) (string, error) {
return "", err
}

defer res.Body.Close()

if res.StatusCode == 200 {
var resp cnmIpam.RequestPoolResponse
err := json.NewDecoder(res.Body).Decode(&resp)
Expand Down Expand Up @@ -135,6 +139,8 @@ func (ic *IpamClient) ReserveIPAddress(poolID string, reservationID string) (str
return "", err
}

defer res.Body.Close()

if res.StatusCode == 200 {
var reserveResp cnmIpam.RequestAddressResponse

Expand Down Expand Up @@ -184,6 +190,8 @@ func (ic *IpamClient) ReleaseIPAddress(poolID string, reservationID string) erro
return err
}

defer res.Body.Close()

if res.StatusCode == 200 {
var releaseResp cnmIpam.ReleaseAddressResponse
err := json.NewDecoder(res.Body).Decode(&releaseResp)
Expand Down Expand Up @@ -227,6 +235,8 @@ func (ic *IpamClient) GetIPAddressUtilization(poolID string) (int, int, []string
return 0, 0, nil, err
}

defer res.Body.Close()

if res.StatusCode == 200 {
var poolInfoResp cnmIpam.GetPoolInfoResponse
err := json.NewDecoder(res.Body).Decode(&poolInfoResp)
Expand Down
2 changes: 2 additions & 0 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ func (reportMgr *ReportManager) SendReport() error {
return fmt.Errorf("[Azure CNI] HTTP Post returned error %v", err)
}

defer res.Body.Close()

if res.StatusCode != 200 {
if res.StatusCode == 400 {
return fmt.Errorf(`"[Azure CNI] HTTP Post returned statuscode %d.
Expand Down