X Tutup
Skip to content

Commit 67d07fe

Browse files
committed
remotes/docker/fetcher.go: Fix missing Close()
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
1 parent b809212 commit 67d07fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

remotes/docker/fetcher.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
148148
})
149149
}
150150

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

154154
if offset > 0 {
@@ -162,13 +162,17 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
162162
if err != nil {
163163
return nil, err
164164
}
165+
defer func() {
166+
if retErr != nil {
167+
resp.Body.Close()
168+
}
169+
}()
165170

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

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

0 commit comments

Comments
 (0)
X Tutup