Fix file descriptor leak in MultiGetAttr

We need to make sure that all children are closed before
return. But the last child saved in parent isn't closed
after we successfully iterate all the files in "names".
This patch fixes this issue.

Fixes #5982

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
This commit is contained in:
Tiwei Bie
2021-05-13 09:08:20 +08:00
parent 29f4b71eb3
commit ddaa36bde5
+4
View File
@@ -1247,6 +1247,7 @@ func (l *localFile) MultiGetAttr(names []string) ([]p9.FullStat, error) {
if parent != l.file.FD() {
// Parent is no longer needed.
_ = unix.Close(parent)
parent = -1
}
if err != nil {
if errors.Is(err, unix.ENOENT) {
@@ -1275,5 +1276,8 @@ func (l *localFile) MultiGetAttr(names []string) ([]p9.FullStat, error) {
}
parent = child
}
if parent != -1 && parent != l.file.FD() {
_ = unix.Close(parent)
}
return stats, nil
}