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

[PATCH 1/2 jk/war-on-sprintf] read_branches_file: plug a FILE* leak

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 23, 2015, 06:02 UTC
Message-ID
<2c89c60e470def8f85941933c9fafe4db314628a.1445579874.git.j6t@kdbg.org>

The earlier rewrite f28e3ab2 (read_branches_file: simplify string handling) of read_branches_file() lost an fclose() call. Put it back.

As on Windows files that are open cannot be removed, the leak manifests in a failure of 'git remote rename origin origin' when the remote's URL is specified in .git/branches/origin, because by the time that the command attempts to remove this file, it is still open.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 remote.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/remote.c b/remote.c
index 1101f82..fb16153 100644
--- a/remote.c
+++ b/remote.c
@@ -282,6 +282,7 @@ static void read_branches_file(struct remote *remote)
 		return;
 
 	strbuf_getline(&buf, f, '\n');
+	fclose(f);
 	strbuf_trim(&buf);
 	if (!buf.len) {
 		strbuf_release(&buf);
-- 
2.3.2.245.gb5bf9d3
Next: Johannes Sixt
Message 1 of 5 in “read_branches_file: plug a FILE* leak”
  1. 1/2 read_branches_file: plug a FILE* leakJohannes Sixt, Oct 23, 2015
  2. 2/2 compat/mingw.c: remove printf format warningJohannes Sixt, Oct 23, 2015
  3. Jeff KingOct 23, 2015
  4. Jeff KingOct 23, 2015
  5. Junio C HamanoOct 23, 2015

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.