From 2a8c023357fc8f150928cdaecdf361925f2dc121 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Fri, 26 Apr 2024 21:01:10 +0800 Subject: [PATCH] fs/inode: using orig_row to ensure correct free logic Signed-off-by: dongjiuzhu1 --- 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 8379361ba32..6eda34bc1a3 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]); }