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
parent
f65643caff
commit
17eef2c679
|
@ -341,15 +341,20 @@ func storageTOTPExportRunE(cmd *cobra.Command, args []string) (err error) {
|
|||
fmt.Println(c.URI())
|
||||
case storageExportFormatPNG:
|
||||
file, _ := os.Create(filepath.Join(dir, fmt.Sprintf("%s.png", c.Username)))
|
||||
defer file.Close()
|
||||
|
||||
if img, err = c.Image(256, 256); err != nil {
|
||||
_ = file.Close()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if err = png.Encode(file, img); err != nil {
|
||||
_ = file.Close()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
_ = file.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue