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 <87569709+nightt5879@users.noreply.github.com>
This commit is contained in:
Nightt 2026-05-24 10:30:56 +08:00 committed by Lup Yuen Lee
parent 2d6cd74215
commit f8a48fa5f3

View file

@ -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);