diff --git a/backend/posix/with_otmpfile.go b/backend/posix/with_otmpfile.go index d5532d20..17abd9bd 100644 --- a/backend/posix/with_otmpfile.go +++ b/backend/posix/with_otmpfile.go @@ -101,6 +101,7 @@ func (p *Posix) openTmpFile(dir, bucket, obj string, size int64, acct auth.Accou if doChown { err := f.Chown(uid, gid) if err != nil { + f.Close() return nil, fmt.Errorf("set temp file ownership: %w", err) } } @@ -141,6 +142,8 @@ func (p *Posix) openMkTemp(dir, bucket, obj string, size int64, dofalloc bool, u if doChown { err := f.Chown(uid, gid) if err != nil { + f.Close() + os.Remove(f.Name()) return nil, fmt.Errorf("set temp file ownership: %w", err) } } diff --git a/backend/posix/without_otmpfile.go b/backend/posix/without_otmpfile.go index 3b144539..7fb35e9d 100644 --- a/backend/posix/without_otmpfile.go +++ b/backend/posix/without_otmpfile.go @@ -61,6 +61,8 @@ func (p *Posix) openTmpFile(dir, bucket, obj string, size int64, acct auth.Accou if doChown { err := f.Chown(uid, gid) if err != nil { + f.Close() + os.Remove(f.Name()) return nil, fmt.Errorf("set temp file ownership: %w", err) } }