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

Also close config file handle when leaving git_config_set_multivar_in_file() early

From
乙酸鋰 <ch3cooli@gmail.com>
Date
Dec 1, 2012, 14:01 UTC
Message-ID
<CAHtLG6SDb5t3ABttbCi5=nVsygf5gLw9DzVtZt0L3WMPNECBWQ@mail.gmail.com>
Hi,

This patch fixes the captioned problem. It is needed because our program statically link git. In this case, do not assume a fail will call die() and exit program so the handle is leave not closed.

Regards, ch3cooli

From 5d8d28f039b4db7b4f040a40fdc2edf866200f0c Mon Sep 17 00:00:00 2001
From: Sup Yut Sum <ch3cooli@gmail.com>
Date: Sat, 1 Dec 2012 21:56:41 +0800
Subject: [PATCH] Also close config file handle when leaving
 git_config_set_multivar_in_file() early
Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
---
 config.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/config.c b/config.c
index fff8a43..4b5c877 100644
--- a/config.c
+++ b/config.c
@@ -1424,6 +1424,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
 		contents = xmmap(NULL, contents_sz, PROT_READ,
 			MAP_PRIVATE, in_fd, 0);
 		close(in_fd);
+		in_fd = -1;
 
 		if (store.seen == 0)
 			store.seen = 1;
@@ -1493,6 +1494,8 @@ out_free:
 	if (lock)
 		rollback_lock_file(lock);
 	free(filename_buf);
+	if (in_fd >= 0)
+		close(in_fd);
 	return ret;
 
 write_err_out:
-- 
1.8.0.msysgit.0
Message 1 of 1 in “Also close config file handle when leaving git_config_set_multivar_in_file() early”
  1. 乙酸鋰Dec 1, 2012

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.