Skip to content

Commit

Permalink
Merge pull request #27 from ThalesIgnite/fix-error-hiding
Browse files Browse the repository at this point in the history
Avoid trampling on existing errors in defer funcs
  • Loading branch information
dmjones authored Jan 25, 2019
2 parents 7e30ee9 + 45cf98d commit 529d2c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crypto11.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ func ConfigureFromFile(configLocation string) (ctx *pkcs11.Ctx, err error) {
return nil, err
}
defer func() {
err = file.Close()
closeErr := file.Close()
if err == nil {
err = closeErr
}
}()

configDecoder := json.NewDecoder(file)
Expand Down
5 changes: 4 additions & 1 deletion keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func findKey(session *PKCS11Session, id []byte, label []byte, keyclass uint, key
return 0, err
}
defer func() {
err = session.Ctx.FindObjectsFinal(session.Handle)
finalErr := session.Ctx.FindObjectsFinal(session.Handle)
if err == nil {
err = finalErr
}
}()
if handles, _, err = session.Ctx.FindObjects(session.Handle, 1); err != nil {
return 0, err
Expand Down

0 comments on commit 529d2c9

Please sign in to comment.