From 9baecf66b815b8c9e6a3250bc3f06b6705780bb8 Mon Sep 17 00:00:00 2001 From: zhangyue Date: Thu, 13 Dec 2018 10:55:49 +0800 Subject: [PATCH] fix: fix defer in loop Signed-off-by: zhangyue --- install.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.go b/install.go index 5e4c6a2c8..4545d4554 100644 --- a/install.go +++ b/install.go @@ -59,7 +59,6 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) if err != nil { return err } - defer r.Close() if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) { d := filepath.Dir(hdr.Name) result := d == "bin" @@ -73,8 +72,10 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) } return result, nil })); err != nil { + r.Close() return err } + r.Close() } return nil }