Close file if permission modification fails

Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
This commit is contained in:
Shiming Zhang 2021-11-15 16:53:48 +08:00
parent 5b09dc5eb0
commit db124c560c

View File

@ -85,6 +85,7 @@ func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
} }
// Call chmod to avoid permission mask // Call chmod to avoid permission mask
if err := os.Chmod(name, perm); err != nil { if err := os.Chmod(name, perm); err != nil {
f.Close()
return nil, err return nil, err
} }
return f, err return f, err