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:
parent
abb83fd23b
commit
59ecf4cae8
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue