fix: 修复close接口中无法正常关闭文件的问题

1. close未考虑保留描述符0、1和2,导致fd合法性判断出现错误,这会导致
上限附近的fd不能被正常的关闭
2. 释放file结构体时未在锁的保护中进行,可能存在问题

fix #I65U8S

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Iaa03a70e18fcb352ca3b99232f50b43d8b13ecf0
This commit is contained in:
Far 2022-12-16 10:53:03 +08:00
parent abb83fd23b
commit 59ecf4cae8
2 changed files with 7 additions and 7 deletions

View File

@ -59,7 +59,7 @@
#define CONFIG_NFILE_DESCRIPTORS 256
#endif
#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS
#define NR_OPEN_DEFAULT (CONFIG_NFILE_DESCRIPTORS - MIN_START_FD)
/* time configure */

View File

@ -288,7 +288,7 @@ static struct File *VfsAttachFile(int fd, UINT32 status)
{
struct File *file = NULL;
if ((fd < 0) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
VFS_ERRNO_SET(EBADF);
return NULL;
}
@ -355,10 +355,10 @@ static int VfsClose(int fd)
LOSCFG_FS_FREE_HOOK((void *)file->fullPath);
}
VfsDetachFile(file);
VfsFilePut(file);
VfsDetachFile(file);
return ret;
}
@ -561,7 +561,7 @@ int close(int fd)
#endif
int ret = (int)LOS_NOK;
if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) {
if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) {
ret = VfsClose(fd);
}
return MapToPosixRet(ret);
@ -603,7 +603,7 @@ ssize_t read(int fd, void *buff, size_t bytes)
#endif
ssize_t ret = (ssize_t)LOS_NOK;
if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) {
if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) {
ret = VfsRead(fd, buff, bytes);
}
@ -633,7 +633,7 @@ ssize_t write(int fd, const void *buff, size_t bytes)
#endif
ssize_t ret = (ssize_t)LOS_NOK;
if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) {
if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) {
ret = VfsWrite(fd, buff, bytes);
}