From 9b41aca70b20f829de249f3b8d42376c87c4f126 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 15 Jul 2024 17:15:09 +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..9bc947187b7d 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) } }