From 78538da3714e74b7e7351631475fa5bd22d92e70 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 20 Apr 2022 09:09:53 -0400 Subject: [PATCH] internal/exec/util/passwd: plug fd leak in error path Doesn't really matter since we'll likely bubble all the way to the exit anyway, but it's good practice. --- internal/exec/util/passwd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/exec/util/passwd.go b/internal/exec/util/passwd.go index 596cf39a7..e6050d049 100644 --- a/internal/exec/util/passwd.go +++ b/internal/exec/util/passwd.go @@ -175,6 +175,7 @@ func writeAuthKeysFile(u *user.User, fp string, keys []byte) error { return fmt.Errorf("opening file %q as user %s and group %s: %w", fp, u.Uid, u.Gid, err) } if _, err = f.Write(keys); err != nil { + f.Close() // ignore errors return fmt.Errorf("writing file %q: %w", fp, err) } if err := f.Close(); err != nil {