From ba426f7782d35f971820a0193cfda58485b92cad Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Tue, 12 Jun 2018 17:03:31 -0700 Subject: Fix reference leak for negative dirents PiperOrigin-RevId: 200306715 Change-Id: I7c80059c77ebd3d9a5d7d48b05c8e7a597f10850 --- pkg/sentry/fs/dirent.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/sentry/fs/dirent.go b/pkg/sentry/fs/dirent.go index a75c7ea7e..554aa30d8 100644 --- a/pkg/sentry/fs/dirent.go +++ b/pkg/sentry/fs/dirent.go @@ -1257,6 +1257,15 @@ func (d *Dirent) destroy() { // Drop all weak references. for _, w := range d.children { + if c := w.Get(); c != nil { + if c.(*Dirent).IsNegative() { + // The parent holds both weak and strong refs in the case of + // negative dirents. + c.DecRef() + } + // Drop the reference we just acquired in WeakRef.Get. + c.DecRef() + } w.Drop() } d.children = nil -- cgit v1.2.3