mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 16:11:56 +08:00
fs/close: move inode to last to void race condition
race condition:
A Thread: B Thread:
close
file_close
filep->inode = NULL
context switch
-------------------> open to alloc same fd
read from IO
filep->f_tag = 0 <-------------------
filep->f_san = 0 -------------------> ioctl(fd, ...)
fdcheck trigger assert
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+4
-4
@@ -162,10 +162,6 @@ int file_close(FAR struct file *filep)
|
||||
ret = file_close_without_clear(filep);
|
||||
if (ret >= 0 && filep->f_inode)
|
||||
{
|
||||
/* Reset the user file struct instance so that it cannot be reused. */
|
||||
|
||||
filep->f_inode = NULL;
|
||||
|
||||
#ifdef CONFIG_FDCHECK
|
||||
filep->f_tag_fdcheck = 0;
|
||||
#endif
|
||||
@@ -173,6 +169,10 @@ int file_close(FAR struct file *filep)
|
||||
#ifdef CONFIG_FDSAN
|
||||
filep->f_tag_fdsan = 0;
|
||||
#endif
|
||||
|
||||
/* Reset the user file struct instance so that it cannot be reused. */
|
||||
|
||||
filep->f_inode = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user