git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] apply: don't leak fd on fdopen() error

From
René Scharfe <l.s.r@web.de>
Date
Apr 5, 2024, 10:58 UTC
Message-ID
<5ba55ee4-94c7-4094-a744-584fc623b391@web.de>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 apply.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/apply.c b/apply.c
index 432837a674..1cfbc2f074 100644
--- a/apply.c
+++ b/apply.c
@@ -4655,8 +4655,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
 			return error_errno(_("cannot open %s"), namebuf);
 	}
 	rej = fdopen(fd, "w");
-	if (!rej)
-		return error_errno(_("cannot open %s"), namebuf);
+	if (!rej) {
+		error_errno(_("cannot open %s"), namebuf);
+		close(fd);
+		return -1;
+	}

 	/* Normal git tools never deal with .rej, so do not pretend
 	 * this is a git patch by saying --git or giving extended
--
2.44.0
Next: Junio C Hamano
Message 1 of 2 in “apply: don't leak fd on fdopen() error”
  1. apply: don't leak fd on fdopen() errorRené Scharfe, Apr 5, 2024
  2. Junio C HamanoApr 5, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.