Skip to content

Commit

Permalink
always close http response body
Browse files Browse the repository at this point in the history
  • Loading branch information
zaibon committed Mar 20, 2020
1 parent 3da7f23 commit 66248f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/capacity/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (s *HTTPStore) Register(nodeID pkg.Identifier, c Capacity, d dmi.DMI, disks
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("wrong response status code received: %v", resp.Status)
}
Expand All @@ -100,6 +102,8 @@ func (s *HTTPStore) Ping(nodeID pkg.Identifier, uptime uint64) error {
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("wrong response status code received: %v", resp.Status)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/flist/flist.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (f *flistModule) downloadFlist(url string) (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
return "", fmt.Errorf("fail to download flist: %v", resp.Status)
Expand Down
2 changes: 2 additions & 0 deletions pkg/identity/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (s *httpIDStore) RegisterNode(node pkg.Identifier, farm pkg.FarmID, version
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusCreated {
return "", fmt.Errorf("wrong response status code received: %v", resp.Status)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/upgrade/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (h *hubClient) Info(flist string) (info flistInfo, err error) {
if response.StatusCode != http.StatusOK {
return info, fmt.Errorf("failed to get flist info: %s", response.Status)
}
defer response.Body.Close()

dec := json.NewDecoder(response.Body)

Expand Down

0 comments on commit 66248f2

Please sign in to comment.