From fe7201245bcc2bb02bcb258c24602b78ce06c332 Mon Sep 17 00:00:00 2001 From: guohao15 Date: Tue, 8 Jul 2025 17:34:30 +0800 Subject: [PATCH] tmpfs:fix memoryleak of tmpfs_opendir fix the memory leak in tmpfs_opendir Signed-off-by: guohao15 --- fs/tmpfs/fs_tmpfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index e4f5f25b320..42f7404e234 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -2047,14 +2047,18 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, { tdir->tf_tdo = tdo; tdir->tf_index = tdo->tdo_nentries; - + *dir = &tdir->tf_base; tmpfs_unlock_directory(tdo); } /* Release the lock on the file system and return the result */ tmpfs_unlock(fs); - *dir = &tdir->tf_base; + if (ret < 0) + { + fs_heap_free(tdir); + } + return ret; }