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

[PATCH] Fix config lockfile handling.

From
Kristian Høgsberg <krh@redhat.com>
Date
Dec 14, 2007, 20:59 UTC
Message-ID
<1197665998-32386-2-git-send-email-krh@redhat.com>
In-Reply-To
<1197665998-32386-1-git-send-email-krh@redhat.com>

When we commit or roll back the lock file the fd is automatically closed, so don't do that again.

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
 config.c |   17 +++--------------
 1 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/config.c b/config.c
index 49d2b42..2e52b17 100644
--- a/config.c
+++ b/config.c
@@ -751,7 +751,7 @@ int git_config_set_multivar(const char* key, const char* value,
 	const char* value_regex, int multi_replace)
 {
 	int i, dot;
-	int fd = -1, in_fd;
+	int fd, in_fd;
 	int ret;
 	char* config_filename;
 	struct lock_file *lock = NULL;
@@ -955,26 +955,15 @@ int git_config_set_multivar(const char* key, const char* value,
 		munmap(contents, contents_sz);
 	}
 
-	if (close(fd) || commit_lock_file(lock) < 0) {
+	if (commit_lock_file(lock) < 0) {
 		fprintf(stderr, "Cannot commit config file!\n");
 		ret = 4;
 		goto out_free;
 	}
 
-	/* fd is closed, so don't try to close it below. */
-	fd = -1;
-	/*
-	 * lock is committed, so don't try to roll it back below.
-	 * NOTE: Since lockfile.c keeps a linked list of all created
-	 * lock_file structures, it isn't safe to free(lock).  It's
-	 * better to just leave it hanging around.
-	 */
-	lock = NULL;
 	ret = 0;
 
 out_free:
-	if (0 <= fd)
-		close(fd);
 	if (lock)
 		rollback_lock_file(lock);
 	free(config_filename);
@@ -1072,7 +1061,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
 	}
 	fclose(config_file);
  unlock_and_out:
-	if (close(out_fd) || commit_lock_file(lock) < 0)
+	if (commit_lock_file(lock) < 0)
 			ret = error("Cannot commit config file!");
  out:
 	free(config_filename);
-- 
1.5.3.4
Previous: Kristian HøgsbergNext: Kristian Høgsberg
Message 2 of 5 in “config.c fixes, take 2”
  1. Kristian HøgsbergDec 14, 2007
  2. Fix config lockfile handling.Kristian Høgsberg, Dec 14, 2007
  3. Use a strbuf for building up section header and key/value pair strings.Kristian Høgsberg, Dec 14, 2007
  4. Junio C HamanoDec 14, 2007
  5. Kristian HøgsbergDec 17, 2007

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.