This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f113d13cbf fs/inode: Fix inoderemove when removing an inode without
parent
f113d13cbf is described below
commit f113d13cbffdd9479c05be83844a5183cbb1381b
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Sat May 24 12:59:52 2025 -0300
fs/inode: Fix inoderemove when removing an inode without parent
This modification ensures that inoderemove will error instead of
trying to remove an inode without parent.
This fix was implement by Richard Jiayang Liu.
Signed-off-by: Richard Jiayang Liu <[email protected]>
---
fs/inode/fs_inoderemove.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c
index ec507adcd4..87c6d63339 100644
--- a/fs/inode/fs_inoderemove.c
+++ b/fs/inode/fs_inoderemove.c
@@ -92,7 +92,16 @@ static FAR struct inode *inode_unlink(FAR const char *path)
else
{
- DEBUGASSERT(desc.parent != NULL);
+ /* The parent could be null if we are trying to remove the
+ * root inode. In that case, fail because we cannot remove it.
+ */
+
+ if (desc.parent == NULL)
+ {
+ inode = NULL;
+ goto errout;
+ }
+
desc.parent->i_child = inode->i_peer;
}
@@ -101,6 +110,7 @@ static FAR struct inode *inode_unlink(FAR const char *path)
atomic_fetch_sub(&inode->i_crefs, 1);
}
+errout:
RELEASE_SEARCH(&desc);
return inode;
}