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

xiaoxiang781216 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 d748a3647a6 fs/hostfs: close host fd on append seek failure
d748a3647a6 is described below

commit d748a3647a6ff88cf35cb8dafb730b7badde5220
Author: chao an <[email protected]>
AuthorDate: Wed Oct 21 13:21:46 2026 +0800

    fs/hostfs: close host fd on append seek failure
    
    hostfs_open() opens the host file before seeking to the end for O_APPEND
    mode.  If the seek fails, the error path freed the hostfs file structure
    but did not close the already-opened host file descriptor.
    
    Route the append seek failure through a cleanup path that closes the host
    file descriptor before freeing the hostfs file structure.
    
    Signed-off-by: chao an <[email protected]>
---
 fs/hostfs/hostfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c
index dcecdbf1aa9..539c938f9c0 100644
--- a/fs/hostfs/hostfs.c
+++ b/fs/hostfs/hostfs.c
@@ -290,7 +290,7 @@ static int hostfs_open(FAR struct file *filep, FAR const 
char *relpath,
         }
       else
         {
-          goto errout_with_buffer;
+          goto errout_with_fd;
         }
     }
 
@@ -313,6 +313,9 @@ static int hostfs_open(FAR struct file *filep, FAR const 
char *relpath,
   ret = OK;
   goto errout_with_lock;
 
+errout_with_fd:
+  host_close(hf->fd);
+
 errout_with_buffer:
   fs_heap_free(hf);
 

Reply via email to