fs/inode: using orig_row to ensure correct free logic

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2024-04-26 21:01:10 +08:00 committed by Xiang Xiao
parent 6542806248
commit 2a8c023357
1 changed files with 5 additions and 6 deletions

View File

@ -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]);
}