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

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


The following commit(s) were added to refs/heads/master by this push:
     new fe7201245bc tmpfs:fix memoryleak of tmpfs_opendir
fe7201245bc is described below

commit fe7201245bcc2bb02bcb258c24602b78ce06c332
Author: guohao15 <[email protected]>
AuthorDate: Tue Jul 8 17:34:30 2025 +0800

    tmpfs:fix memoryleak of tmpfs_opendir
    
    fix the memory leak in tmpfs_opendir
    
    Signed-off-by: guohao15 <[email protected]>
---
 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;
 }
 

Reply via email to