summaryrefslogtreecommitdiffhomepage
path: root/runsc/fsgofer/fsgofer.go
diff options
context:
space:
mode:
authorTiwei Bie <tiwei.btw@antgroup.com>2021-05-12 22:59:21 +0800
committerTiwei Bie <tiwei.btw@antgroup.com>2021-05-13 09:08:20 +0800
commitddaa36bde5c55067ca866dbfcbd2e560e3bb356d (patch)
treeb5583243c5a17dddf5251a7ad6bbff502dd86564 /runsc/fsgofer/fsgofer.go
parent29f4b71eb3db3d082735bd4316006d6bcc3230a1 (diff)
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>
Diffstat (limited to 'runsc/fsgofer/fsgofer.go')
-rw-r--r--runsc/fsgofer/fsgofer.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/runsc/fsgofer/fsgofer.go b/runsc/fsgofer/fsgofer.go
index b81ede5ae..3f362b25e 100644
--- a/runsc/fsgofer/fsgofer.go
+++ b/runsc/fsgofer/fsgofer.go
@@ -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
}