Skip to content

Commit 2b95c34

Browse files
wdfk-progRbb666
authored andcommitted
fix[dfs_v1]: prevent vnode ref underflow and double release on close/fd release
1 parent 88c1e6c commit 2b95c34

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

components/dfs/dfs_v1/src/dfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,16 @@ void fdt_fd_release(struct dfs_fdtable* fdt, int fd)
414414
if (fd_slot->ref_count == 0)
415415
{
416416
struct dfs_vnode *vnode = fd_slot->vnode;
417+
fd_slot->vnode = RT_NULL;
417418
if (vnode)
418419
{
419-
vnode->ref_count--;
420+
if (vnode->ref_count > 0)
421+
{
422+
vnode->ref_count--;
423+
}
420424
if(vnode->ref_count == 0)
421425
{
422426
rt_free(vnode);
423-
fd_slot->vnode = RT_NULL;
424427
}
425428
}
426429
rt_free(fd_slot);

components/dfs/dfs_v1/src/dfs_file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ int dfs_file_close(struct dfs_file *fd)
337337
dfs_fm_lock();
338338
vnode = fd->vnode;
339339

340-
if (vnode->ref_count <= 0)
340+
if (vnode == NULL || vnode->ref_count <= 0)
341341
{
342342
dfs_fm_unlock();
343343
return -ENXIO;
@@ -348,11 +348,12 @@ int dfs_file_close(struct dfs_file *fd)
348348
result = vnode->fops->close(fd);
349349
}
350350

351-
if (vnode->ref_count == 1)
351+
vnode->ref_count--;
352+
fd->vnode = NULL;
353+
if (vnode->ref_count == 0)
352354
{
353355
/* remove from hash */
354356
rt_list_remove(&vnode->list);
355-
fd->vnode = NULL;
356357

357358
if (vnode->path != vnode->fullpath)
358359
{

0 commit comments

Comments
 (0)