Do not attempt to clear release dentries if fs.root is nil.

When initializing the fs.client and fs.root fails, the filesystem is released.
The release implementation panics when leak checking is enabled (in tests)
because it lacks nil-checks for fs.root.

PiperOrigin-RevId: 428976387
This commit is contained in:
Ayush Ranjan
2022-02-16 00:43:36 -08:00
committed by gVisor bot
parent ae089adbb2
commit 12a9efa29c
+3 -2
View File
@@ -697,8 +697,9 @@ func (fs *filesystem) Release(ctx context.Context) {
// If leak checking is enabled, release all outstanding references in the
// filesystem. We deliberately avoid doing this outside of leak checking; we
// have released all external resources above rather than relying on dentry
// destructors.
if refs_vfs1.GetLeakMode() != refs_vfs1.NoLeakChecking {
// destructors. fs.root may be nil if creating the client or initializing the
// root dentry failed in GetFilesystem.
if refs_vfs1.GetLeakMode() != refs_vfs1.NoLeakChecking && fs.root != nil {
fs.renameMu.Lock()
fs.root.releaseSyntheticRecursiveLocked(ctx)
fs.evictAllCachedDentriesLocked(ctx)