From 85b4dc33e8e81f8715cf3feb982d6afae33cf9c4 Mon Sep 17 00:00:00 2001 From: my-git9 Date: Thu, 28 Jul 2022 22:47:27 +0800 Subject: [PATCH] fix: Add logic to handle for f.Close() for util/db (#9963) (#10127) Signed-off-by: xin.li --- util/db/gpgkeys.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/db/gpgkeys.go b/util/db/gpgkeys.go index 8a03c35bd45ca..1c051a1c5f705 100644 --- a/util/db/gpgkeys.go +++ b/util/db/gpgkeys.go @@ -24,7 +24,12 @@ func validatePGPKey(keyData string) (*appsv1.GnuPGPublicKey, error) { if err != nil { return nil, err } - defer f.Close() + defer func() { + err = f.Close() + if err != nil { + log.Errorf("error closing file %q: %v", f.Name(), err) + } + }() parsed, err := gpg.ValidatePGPKeys(f.Name()) if err != nil {