From 285acec5b346ee65202141f734ce6c1fee3536a9 Mon Sep 17 00:00:00 2001 From: angryproton Date: Sun, 12 Jul 2026 16:49:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[fix][dfs=5Felm]=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=9B=AE=E5=BD=95=E5=92=8C=E9=87=8A=E6=94=BE?= =?UTF-8?q?vnode=E6=97=B6=E7=9A=84=E8=B5=84=E6=BA=90=E6=B3=84=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dfs/dfs_v1/filesystems/elmfat/dfs_elm.c | 1 + .../dfs/dfs_v2/filesystems/elmfat/dfs_elm.c | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c index afb2a0d46d9..ee997d4087e 100644 --- a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c @@ -478,6 +478,7 @@ int dfs_elm_close(struct dfs_file *file) dir = (DIR *)(file->data); RT_ASSERT(dir != RT_NULL); + f_closedir(dir); /* release memory */ rt_free(dir); } diff --git a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c index cb1479f6ca9..b243d10432a 100644 --- a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c @@ -522,6 +522,7 @@ int dfs_elm_close(struct dfs_file *file) dir = (DIR *)(file->vnode->data); RT_ASSERT(dir != RT_NULL); + f_closedir(dir); /* release memory */ rt_free(dir); } @@ -1014,10 +1015,27 @@ static struct dfs_vnode *dfs_elm_create_vnode(struct dfs_dentry *dentry, int typ static int dfs_elm_free_vnode(struct dfs_vnode *vnode) { - /* nothing to be freed */ - if (vnode && vnode->ref_count <= 1) + /* free_vnode is the backstop destruction point: called from + dfs_vnode_unref when ref_count drops to 0, and from dfs_vnode_destroy on + a create/lookup failure (ref_count == 1). Normally dfs_elm_close has + already released the resource and set data = NULL, so this is a no-op. + It only tears down the resource when close bailed out early due to + ref_count > 1 (a transient lookup had raised it), which is exactly the + leak this guards against. data != NULL means the resource is still + live and the lock is still initialized, so both are released here. */ + if (vnode && vnode->ref_count <= 1 && vnode->data != RT_NULL) { - vnode->data = NULL; + if (vnode->type == FT_DIRECTORY) + { + f_closedir((DIR *)vnode->data); + } + else if (vnode->type == FT_REGULAR) + { + f_close((FIL *)vnode->data); + } + rt_free(vnode->data); + vnode->data = RT_NULL; + rt_mutex_detach(&vnode->lock); } return 0; From 6f117d445339510b63f08f61c14fd29cf33f24cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8E=E9=9D=9E=E7=86=8A?= <38059101+Unbear-Hz@users.noreply.github.com> Date: Sun, 12 Jul 2026 17:19:07 +0800 Subject: [PATCH 2/2] [chg][dfs]Clean up comments in dfs_elm_free_vnode Removed unnecessary comments from dfs_elm_free_vnode function. --- components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c index b243d10432a..8d29785f639 100644 --- a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c @@ -1015,14 +1015,6 @@ static struct dfs_vnode *dfs_elm_create_vnode(struct dfs_dentry *dentry, int typ static int dfs_elm_free_vnode(struct dfs_vnode *vnode) { - /* free_vnode is the backstop destruction point: called from - dfs_vnode_unref when ref_count drops to 0, and from dfs_vnode_destroy on - a create/lookup failure (ref_count == 1). Normally dfs_elm_close has - already released the resource and set data = NULL, so this is a no-op. - It only tears down the resource when close bailed out early due to - ref_count > 1 (a transient lookup had raised it), which is exactly the - leak this guards against. data != NULL means the resource is still - live and the lock is still initialized, so both are released here. */ if (vnode && vnode->ref_count <= 1 && vnode->data != RT_NULL) { if (vnode->type == FT_DIRECTORY)