From 2a577a7bae37e5731dceaea8740683573b6b70a5 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 15 Jul 2024 21:05:42 +0800 Subject: [PATCH] fix: close file when failed to open gzip (#7164) 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) } }