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

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

commit f8a48fa5f35f5d6aaceb66859dac578d6fdaff13
Author: Nightt <[email protected]>
AuthorDate: Sun May 24 10:30:56 2026 +0800

    testing/sd_stress: Harden file creation cleanup
    
    Close the temporary file descriptor when create_files() fails after open(), 
and release the read buffer before returning from the path-length failure 
branch.
    
    This is logically separable from the #3205 stale-directory fix: it does not 
change how existing /sd/stress is handled, but keeps the same failure paths 
from leaking resources while the stress test exits after an error.
    
    The scope intentionally stays within sd_stress failure cleanup and does not 
touch SD/MMC transfer behavior or other testing drivers.
    
    Signed-off-by: Nightt <[email protected]>
---
 testing/drivers/sd_stress/sd_stress_main.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/testing/drivers/sd_stress/sd_stress_main.c 
b/testing/drivers/sd_stress/sd_stress_main.c
index 882bec362..dffdd16c5 100644
--- a/testing/drivers/sd_stress/sd_stress_main.c
+++ b/testing/drivers/sd_stress/sd_stress_main.c
@@ -233,6 +233,7 @@ static bool create_files(const char *dir, const char *name,
   if (path_len + 5 >= MAX_PATH_LEN)
     {
       printf("path name too long\n");
+      free(read_bytes);
       return false;
     }
 
@@ -267,7 +268,7 @@ static bool create_files(const char *dir, const char *name,
           printf("write %s failed, ret: %d, errno %d -> %s\n",
                  path, ret, errno, strerror(errno));
           passed = false;
-          break;
+          goto close_file;
         }
 
       ret = lseek(fd, 0, SEEK_SET);
@@ -277,7 +278,7 @@ static bool create_files(const char *dir, const char *name,
           printf("lseek %s failed, ret: %d, errno %d -> %s\n",
                  path, ret, errno, strerror(errno));
           passed = false;
-          break;
+          goto close_file;
         }
 
       ret = read(fd, read_bytes, num_bytes);
@@ -287,16 +288,17 @@ static bool create_files(const char *dir, const char 
*name,
           printf("read %s failed, ret: %d, errno %d -> %s\n",
                  path, ret, errno, strerror(errno));
           passed = false;
-          break;
+          goto close_file;
         }
 
       if (memcmp(read_bytes, bytes, num_bytes) != 0)
         {
           printf("read and write buffers are not the same\n");
           passed = false;
-          break;
+          goto close_file;
         }
 
+close_file:
       ret = close(fd);
 
       if (ret < 0)
@@ -306,6 +308,11 @@ static bool create_files(const char *dir, const char *name,
           passed = false;
           break;
         }
+
+      if (!passed)
+        {
+          break;
+        }
     }
 
   free(read_bytes);

Reply via email to