Skip to content

Commit b890f05

Browse files
committed
Fix content.ReaderAt close
Signed-off-by: Shiming Zhang <[email protected]>
1 parent 01ca105 commit b890f05

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

cmd/ctr/commands/snapshots/snapshots.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ var diffCommand = cli.Command{
164164
if err != nil {
165165
return err
166166
}
167+
defer ra.Close()
167168
_, err = io.Copy(os.Stdout, content.NewReader(ra))
168169

169170
return err

content/testsuite/testsuite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ func checkSmallBlob(ctx context.Context, t *testing.T, store content.Store) {
780780
if err != nil {
781781
t.Fatal(err)
782782
}
783+
defer ra.Close()
783784
r := io.NewSectionReader(ra, 0, readSize)
784785
b, err := ioutil.ReadAll(r)
785786
if err != nil {

images/archive/importer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
281281
}
282282
s, err := compression.DecompressStream(content.NewReader(ra))
283283
if err != nil {
284+
ra.Close()
284285
return nil, errors.Wrapf(err, "failed to detect compression for %q", layerFiles[i])
285286
}
286287
if s.GetCompression() == compression.Uncompressed {
@@ -292,6 +293,7 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
292293
layers[i], err = compressBlob(ctx, store, s, ref, content.WithLabels(labels))
293294
if err != nil {
294295
s.Close()
296+
ra.Close()
295297
return nil, err
296298
}
297299
layers[i].MediaType = images.MediaTypeDockerSchema2LayerGzip
@@ -302,7 +304,7 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
302304
layers[i].MediaType = images.MediaTypeDockerSchema2LayerGzip
303305
}
304306
s.Close()
305-
307+
ra.Close()
306308
}
307309
return layers, nil
308310
}

install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
6666
cr := content.NewReader(ra)
6767
r, err := compression.DecompressStream(cr)
6868
if err != nil {
69+
ra.Close()
6970
return err
7071
}
7172
if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) {
@@ -87,9 +88,11 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
8788
return result, nil
8889
})); err != nil {
8990
r.Close()
91+
ra.Close()
9092
return err
9193
}
9294
r.Close()
95+
ra.Close()
9396
}
9497
return nil
9598
}

0 commit comments

Comments
 (0)