summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Lackner2017-11-28 00:11:15 +0100
committerrfjakob2017-11-28 09:28:06 +0100
commit8c5069c6374778bab17cd640b2579c936c635fa7 (patch)
tree02fe59f0eb35cbd44d4a6f1e23e1d773b275d72a
parent72b975867a3b9bdf53fc2da62e2ba4a328d7e4ab (diff)
syscallcompat: Fix Fchownat syscall wrapper on darwin
* Acquire the lock before reading the current directory * Fix a file descriptor leak
-rw-r--r--internal/syscallcompat/sys_darwin.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index 5bc5fba..5504860 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -134,12 +134,13 @@ func Dup3(oldfd int, newfd int, flags int) (err error) {
// Poor man's Fchownat.
func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) {
+ chdirMutex.Lock()
+ defer chdirMutex.Unlock()
cwd, err := syscall.Open(".", syscall.O_RDONLY, 0)
if err != nil {
return err
}
- chdirMutex.Lock()
- defer chdirMutex.Unlock()
+ defer syscall.Close(cwd)
err = syscall.Fchdir(dirfd)
if err != nil {
return err