From 3c46c19c324802faff33e4662016ffe3c9b9c0a3 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 15 Jul 2024 20:24:10 +0800 Subject: [PATCH] fix: close file when failed to open gzip Signed-off-by: guoguangwu --- pkg/fanal/image/docker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/fanal/image/docker.go b/pkg/fanal/image/docker.go index 54096099761f..ea1549b0f910 100644 --- a/pkg/fanal/image/docker.go +++ b/pkg/fanal/image/docker.go @@ -35,6 +35,7 @@ func fileOpener(fileName string) func() (io.ReadCloser, error) { if utils.IsGzip(br) { r, err = gzip.NewReader(br) if err != nil { + _ = f.Close() return nil, xerrors.Errorf("failed to open gzip: %w", err) } }