[PATCH 4/4] t/helper/test-delta: close fd if fstat() fails after second open()
- From
Hoyoung Lee <lhywkd22@gmail.com>
- Date
- Jul 22, 2025, 07:36 UTC
- Message-ID
- <20250722073634.1080217-5-lhywkd22@gmail.com>
- In-Reply-To
- <20250722073634.1080217-1-lhywkd22@gmail.com>
When opening argv[3], if open() succeeds but fstat() fails, the file descriptor is not closed, resulting in a resource leak. This patch ensures that the descriptor is closed on failure.
Signed-off-by: Hoyoung Lee <lhywkd22@gmail.com> --- t/helper/test-delta.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index 103bf7f3e9..ba2d897aa3 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -46,6 +46,8 @@ int cmd__delta(int argc, const char **argv) fd = open(argv[3], O_RDONLY); if (fd < 0 || fstat(fd, &st)) { perror(argv[3]); + if (fd >= 0) + close(fd); goto cleanup; } data_size = st.st_size;
-- 2.34.1