Skip to content

Commit

Permalink
fix: move defer after error to protect panic case (#1670)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
spiffcs authored Mar 15, 2023
1 parent e314006 commit 61362c0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion syft/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 61362c0

Please sign in to comment.