Skip to content

Commit

Permalink
remotes/docker/fetcher.go: Fix missing Close()
Browse files Browse the repository at this point in the history
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
(cherry picked from commit 67d07fe)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
wzshiming authored and thaJeztah committed Jul 21, 2021
1 parent e4418db commit 06c90e7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions remotes/docker/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
})
}

func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string, offset int64) (io.ReadCloser, error) {
func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string, offset int64) (_ io.ReadCloser, retErr error) {
req.header.Set("Accept", strings.Join([]string{mediatype, `*/*`}, ", "))

if offset > 0 {
Expand All @@ -162,13 +162,17 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
if err != nil {
return nil, err
}
defer func() {
if retErr != nil {
resp.Body.Close()
}
}()

if resp.StatusCode > 299 {
// TODO(stevvooe): When doing a offset specific request, we should
// really distinguish between a 206 and a 200. In the case of 200, we
// can discard the bytes, hiding the seek behavior from the
// implementation.
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return nil, errors.Wrapf(errdefs.ErrNotFound, "content at %v not found", req.String())
Expand Down

0 comments on commit 06c90e7

Please sign in to comment.