fusefrontend: fix fd leak in error path
This commit is contained in:
parent
77c3df48ef
commit
cd0ec342b9
|
@ -67,16 +67,15 @@ func (fs *FS) decryptPathAt(dirfd int, cipherPath string) (plainPath string, err
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Descend into next directory
|
// Descend into next directory
|
||||||
oldWd := wd
|
|
||||||
wd, err = syscallcompat.Openat(wd, part, syscall.O_NOFOLLOW, 0)
|
wd, err = syscallcompat.Openat(wd, part, syscall.O_NOFOLLOW, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// Unless we are in the first iteration, where dirfd is our wd, close
|
// Yes this is somewhat wasteful in terms of used file descriptors:
|
||||||
// the old working directory.
|
// we keep them all open until the function returns. But it is simple
|
||||||
if i > 0 {
|
// and reliable.
|
||||||
syscall.Close(oldWd)
|
defer syscall.Close(wd)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return plainPath, nil
|
return plainPath, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue