From 927d1d668a8e995d37bbe9b5d75d633b44e66c94 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Thu, 26 Mar 2026 15:43:47 -0700 Subject: [PATCH] fix: cleanup file descriptor leaks with chown fails We were missing a few cases of cleaning up temp files and file descriptors in the openTmpFile Chown() error cases. --- backend/posix/with_otmpfile.go | 3 +++ backend/posix/without_otmpfile.go | 2 ++ 2 files changed, 5 insertions(+) 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) } }