From ddaa36bde5c55067ca866dbfcbd2e560e3bb356d Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Wed, 12 May 2021 22:59:21 +0800 Subject: 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 --- runsc/fsgofer/fsgofer.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runsc/fsgofer') 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 } -- cgit v1.2.3