[PATCH] cpukit/dosfs: Don't leak a FAT FD

Kinsey Moore kinsey.moore at oarcorp.com
Tue Jan 16 19:42:28 UTC 2024


The tmp_fat_fd variable is unconditionally opened in the branch where it
is used within the loop and so must be closed or else risk a resource
leak.
---
 cpukit/libfs/src/dosfs/msdos_dir.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c
index 4ae2c32415..d9585635d9 100644
--- a/cpukit/libfs/src/dosfs/msdos_dir.c
+++ b/cpukit/libfs/src/dosfs/msdos_dir.c
@@ -339,14 +339,14 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
                     iop->offset = iop->offset + sizeof(struct dirent);
                     cmpltd += (sizeof(struct dirent));
                     count -= (sizeof(struct dirent));
+                }
 
-                    /* inode number extracted, close fat-file */
-                    rc = fat_file_close(&fs_info->fat, tmp_fat_fd);
-                    if (rc != RC_OK)
-                    {
-                        msdos_fs_unlock(fs_info);
-                        return rc;
-                    }
+                /* inode number extracted, close fat-file */
+                rc = fat_file_close(&fs_info->fat, tmp_fat_fd);
+                if (rc != RC_OK)
+                {
+                    msdos_fs_unlock(fs_info);
+                    return rc;
                 }
             }
 
-- 
2.39.2



More information about the devel mailing list