From db7df3ab2a840bc927417a84448263885b3e21ff Mon Sep 17 00:00:00 2001 From: David Son Date: Thu, 18 Jan 2024 18:49:57 +0000 Subject: [PATCH] Fix file descriptor leak Signed-off-by: David Son --- fs/unpacker.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/unpacker.go b/fs/unpacker.go index fcac328f3..82feb8e9a 100644 --- a/fs/unpacker.go +++ b/fs/unpacker.go @@ -77,18 +77,19 @@ func (lu *layerUnpacker) Unpack(ctx context.Context, desc ocispec.Descriptor, mo if err != nil { return fmt.Errorf("cannot fetch layer: %w", err) } - defer rc.Close() if !local { - if err = lu.fetcher.Store(ctx, desc, rc); err != nil { + err := lu.fetcher.Store(ctx, desc, rc) + rc.Close() + if err != nil { return fmt.Errorf("cannot store layer: %w", err) } - rc.Close() rc, _, err = lu.fetcher.Fetch(ctx, desc) if err != nil { return fmt.Errorf("cannot fetch layer: %w", err) } } + defer rc.Close() parents, err := getLayerParents(mounts[0].Options) if err != nil { return fmt.Errorf("cannot get layer parents: %w", err)