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())
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue