Skip to content

Commit

Permalink
Fix some error cases where a HTTP body might not be closed
Browse files Browse the repository at this point in the history
  • Loading branch information
titanous committed Oct 8, 2013
1 parent 2d425af commit e906485
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ func (r *Registry) GetRemoteHistory(imgID, registry string, token []string) ([]s
}
req.Header.Set("Authorization", "Token "+strings.Join(token, ", "))
res, err := doWithCookies(r.client, req)
if err != nil || res.StatusCode != 200 {
if res != nil {
if res.StatusCode == 401 {
return nil, ErrLoginRequired
}
return nil, utils.NewHTTPRequestError(fmt.Sprintf("Internal server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
}
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
if res.StatusCode == 401 {
return nil, ErrLoginRequired
}
return nil, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
}

jsonString, err := ioutil.ReadAll(res.Body)
if err != nil {
Expand Down Expand Up @@ -240,6 +240,7 @@ func (r *Registry) GetRemoteImageLayer(imgID, registry string, token []string) (
return nil, err
}
if res.StatusCode != 200 {
res.Body.Close()
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
res.StatusCode, imgID)
}
Expand Down

0 comments on commit e906485

Please sign in to comment.