From f668c71545c18bcb193730cdc42e28ca4ac782c9 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 29 Sep 2023 13:17:22 +0200 Subject: [PATCH] Defer only after checking err. Signed-off-by: Felix Fontein --- cmd/sops/common/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/sops/common/common.go b/cmd/sops/common/common.go index 7beecb8c1..fa54ecc7d 100644 --- a/cmd/sops/common/common.go +++ b/cmd/sops/common/common.go @@ -321,10 +321,10 @@ func FixAWSKMSEncryptionContextBug(opts GenericDecryptOpts, tree *sops.Tree) (*s } file, err := os.Create(opts.InputPath) - defer file.Close() if err != nil { return nil, NewExitError(fmt.Sprintf("Could not open file for writing: %s", err), codes.CouldNotWriteOutputFile) } + defer file.Close() _, err = file.Write(encryptedFile) if err != nil { return nil, err