fix(commands): explicitly close files (#3031)

This fixes an issue that could potentially cause problems with open files due to a deferred file close in a for loop.
pull/3033/head
James Elliott 2022-03-17 16:53:07 +11:00 committed by GitHub
parent f65643caff
commit 17eef2c679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -341,15 +341,20 @@ func storageTOTPExportRunE(cmd *cobra.Command, args []string) (err error) {
fmt.Println(c.URI()) fmt.Println(c.URI())
case storageExportFormatPNG: case storageExportFormatPNG:
file, _ := os.Create(filepath.Join(dir, fmt.Sprintf("%s.png", c.Username))) file, _ := os.Create(filepath.Join(dir, fmt.Sprintf("%s.png", c.Username)))
defer file.Close()
if img, err = c.Image(256, 256); err != nil { if img, err = c.Image(256, 256); err != nil {
_ = file.Close()
return err return err
} }
if err = png.Encode(file, img); err != nil { if err = png.Encode(file, img); err != nil {
_ = file.Close()
return err return err
} }
_ = file.Close()
} }
} }