fix: move defer after error to protect panic case (#1670)

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
Christopher Angelo Phillips
2023-03-15 15:29:10 -04:00
committed by GitHub
parent e3140063d4
commit 61362c04fa
+1 -1
View File
@@ -385,11 +385,11 @@ func (s *Source) SetID() {
case FileScheme:
// attempt to use the digest of the contents of the file as the ID
file, err := os.Open(s.Metadata.Path)
defer file.Close()
if err != nil {
d = digest.FromString(s.Metadata.Path).String()
break
}
defer file.Close()
di, err := digest.FromReader(file)
if err != nil {
d = digest.FromString(s.Metadata.Path).String()