git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hoyoung Lee <lhywkd22@gmail.com>
To: git@vger.kernel.org
Cc: Hoyoung Lee <lhywkd22@gmail.com>
Subject: [PATCH 4/4] t/helper/test-delta: close fd if fstat() fails after second open()
Date: Tue, 22 Jul 2025 07:36:34 +0000	[thread overview]
Message-ID: <20250722073634.1080217-5-lhywkd22@gmail.com> (raw)
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


      parent reply	other threads:[~2025-07-22  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22  7:36 [PATCH 0/4] Fix resource leaks in various helpers and builtin commands Hoyoung Lee
2025-07-22  7:36 ` [PATCH 1/4] t/helper/test-truncate: close file descriptor after truncation Hoyoung Lee
2025-07-22  7:36 ` [PATCH 2/4] builtin/archive: close file descriptor on dup2() failure Hoyoung Lee
2025-07-22  7:36 ` [PATCH 3/4] t/helper/test-delta: close fd if fstat() fails after open() Hoyoung Lee
2025-07-22  7:36 ` Hoyoung Lee [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250722073634.1080217-5-lhywkd22@gmail.com \
    --to=lhywkd22@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).