summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
diff options
context:
space:
mode:
authorDean Deng <deandeng@google.com>2020-10-13 01:11:00 -0700
committergVisor bot <gvisor-bot@google.com>2020-10-13 01:13:22 -0700
commit577c82f22c6c175240fa52fee560f39aaa7db3a7 (patch)
tree9caece3c29217370e14e7c89de4a043e33df9a0f /pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
parentfc7df53222e56fdce7dee002f1fb4c332de616af (diff)
[vfs2] Add FilesystemType.Release to avoid reference leaks.
Singleton filesystem like devpts and devtmpfs have a single filesystem shared among all mounts, so they acquire a "self-reference" when initialized that must be released when the entire virtual filesystem is released at sandbox exit. PiperOrigin-RevId: 336828852
Diffstat (limited to 'pkg/sentry/fsimpl/devtmpfs/devtmpfs.go')
-rw-r--r--pkg/sentry/fsimpl/devtmpfs/devtmpfs.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
index 6d1753080..ed729e480 100644
--- a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
+++ b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
@@ -71,6 +71,15 @@ func (fst *FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virtua
return fst.fs, fst.root, nil
}
+// Release implements vfs.FilesystemType.Release.
+func (fst *FilesystemType) Release(ctx context.Context) {
+ if fst.fs != nil {
+ // Release the original reference obtained when creating the filesystem.
+ fst.root.DecRef(ctx)
+ fst.fs.DecRef(ctx)
+ }
+}
+
// Accessor allows devices to create device special files in devtmpfs.
type Accessor struct {
vfsObj *vfs.VirtualFilesystem