You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/08 17:24:16 UTC

(nuttx) 02/02: fs/inode: using orig_row to ensure correct free logic

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 2a8c023357fc8f150928cdaecdf361925f2dc121
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Fri Apr 26 21:01:10 2024 +0800

    fs/inode: using orig_row to ensure correct free logic
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 fs/inode/fs_files.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c
index 8379361ba3..6eda34bc1a 100644
--- a/fs/inode/fs_files.c
+++ b/fs/inode/fs_files.c
@@ -90,18 +90,17 @@ static int files_extend(FAR struct filelist *list, size_t row)
   int i;
   int j;
 
-  if (row <= list->fl_rows)
+  orig_rows = list->fl_rows;
+  if (row <= orig_rows)
     {
       return 0;
     }
 
-  if (files_countlist(list) > OPEN_MAX)
+  if (CONFIG_NFILE_DESCRIPTORS_PER_BLOCK * orig_rows > OPEN_MAX)
     {
       return -EMFILE;
     }
 
-  orig_rows = list->fl_rows;
-
   files = kmm_malloc(sizeof(FAR struct file *) * row);
   DEBUGASSERT(files);
   if (files == NULL)
@@ -109,14 +108,14 @@ static int files_extend(FAR struct filelist *list, size_t row)
       return -ENFILE;
     }
 
-  i = list->fl_rows;
+  i = orig_rows;
   do
     {
       files[i] = kmm_zalloc(sizeof(struct file) *
                             CONFIG_NFILE_DESCRIPTORS_PER_BLOCK);
       if (files[i] == NULL)
         {
-          while (--i >= list->fl_rows)
+          while (--i >= orig_rows)
             {
               kmm_free(files[i]);
             }