From d861cd5f14bc42b32eeac20c444a685f1d9748f7 Mon Sep 17 00:00:00 2001 From: Dean Deng Date: Mon, 12 Oct 2020 10:39:03 -0700 Subject: [vfs2] Don't leak disconnected mounts. PiperOrigin-RevId: 336694658 --- pkg/sentry/kernel/kernel.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pkg/sentry/kernel') diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index d6c21adb7..16c427fc8 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -1738,3 +1738,18 @@ func (k *Kernel) ShmMount() *vfs.Mount { func (k *Kernel) SocketMount() *vfs.Mount { return k.socketMount } + +// Release releases resources owned by k. +// +// Precondition: This should only be called after the kernel is fully +// initialized, e.g. after k.Start() has been called. +func (k *Kernel) Release() { + if VFS2Enabled { + ctx := k.SupervisorContext() + k.hostMount.DecRef(ctx) + k.pipeMount.DecRef(ctx) + k.shmMount.DecRef(ctx) + k.socketMount.DecRef(ctx) + k.vfs.Release(ctx) + } +} -- cgit v1.2.3