Skip to contentSkip to conversation

xfs_repair: don't leak the rootdir inode when orphanage already exists

PATCH In review Darrick J. Wong 2 participants 2 messages Jun 18, 2024 – Jun 19, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_repair: don't leak the rootdir inode when orphanage already exists

From: Darrick J. Wong <[email protected]>

If repair calls mk_orphanage and the /lost+found directory already exists, we need to irele the root directory before exiting the function.

Fixes 6c39a3cbda32 ("Don't trash lost+found in phase 4 Merge of master-melb:xfs-cmds:29144a by kenmcd.")
---
 repair/phase6.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
repair/phase6.c +5 -2
index ae8935a26420..e6103f768988 100644
@@ -919,8 +919,10 @@ mk_orphanage(xfs_mount_t *mp)
 	xname.len = strlen(ORPHANAGE);
 	xname.type = XFS_DIR3_FT_DIR;
 
-	if (libxfs_dir_lookup(NULL, pip, &xname, &ino, NULL) == 0)
-		return ino;
+	/* If the lookup of /lost+found succeeds, return the inumber. */
+	error = -libxfs_dir_lookup(NULL, pip, &xname, &ino, NULL);
+	if (error == 0)
+		goto out_pip;
 
 	/*
 	 * could not be found, create it
@@ -1012,6 +1014,7 @@ mk_orphanage(xfs_mount_t *mp)
 			ORPHANAGE, error);
 	}
 	libxfs_irele(ip);
+out_pip:
 	libxfs_irele(pip);
 
 	return(ino);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If repair calls mk_orphanage and the /lost+found directory already exists, we need to irele the root directory before exiting the function.

Fixes 6c39a3cbda32 ("Don't trash lost+found in phase 4 Merge of master-melb:xfs-cmds:29144a by kenmcd.")

Looks good: