From 03b7bd9cf1f85d7499daf345c28b89112018f519 Mon Sep 17 00:00:00 2001 From: ligd Date: Thu, 24 Jun 2021 22:06:29 +0800 Subject: [PATCH] fs: move out nx_close from filelock Change-Id: Ia6c4ec88d90db0330134d0aaa30e94cb71c8a066 Signed-off-by: ligd --- fs/inode/fs_files.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 1669cb45739..838dcbddb4b 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -484,6 +484,8 @@ int dup2(int fd1, int fd2) int nx_close(int fd) { FAR struct filelist *list; + FAR struct file *filep; + FAR struct file file; int ret; /* Get the thread-specific file list. It should never be NULL in this @@ -511,11 +513,14 @@ int nx_close(int fd) return -EBADF; } - ret = file_close(&list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK] - [fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]); + filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK] + [fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]; + memcpy(&file, filep, sizeof(struct file)); + memset(filep, 0, sizeof(struct file)); + _files_semgive(list); - return ret; + return file_close(&file); } /****************************************************************************