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

Re: [PATCH] Release config lock if the regex is invalid

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 8, 2006, 00:32 UTC
Message-ID
<Pine.LNX.4.63.0605080229220.32508@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<20060507213612.27887.28600.stgit@dv.roinet.com>
Hi,
On Sun, 7 May 2006, Pavel Roskin wrote:
Show 10 quoted lines
> @@ -516,6 +516,8 @@ int git_config_set_multivar(const char* 
>  				fprintf(stderr, "Invalid pattern: %s\n",
>  					value_regex);
>  				free(store.value_regex);
> +				close(fd);
> +				unlink(lock_file);
>  				ret = 6;
>  				goto out_free;
>  			}
> 

This is not enough. There are quite a few exit paths. Notice the "goto out_free"? That is where this must go.

This patch is totally untested but obviously correct:
diff --git a/config.c b/config.c
index 30effe3..d8fd94d 100644
--- a/config.c
+++ b/config.c
@@ -445,7 +445,7 @@ int git_config_set_multivar(const char* 
 	const char* value_regex, int multi_replace)
 {
 	int i;
-	int fd;
+	int fd = -1;
 	int ret;
 	char* config_filename = strdup(git_path("config"));
 	char* lock_file = strdup(git_path("config.lock"));
@@ -619,10 +619,14 @@ int git_config_set_multivar(const char* 
 	ret = 0;
 
 out_free:
+	if (fd > 0)
+		close(fd);
 	if (config_filename)
 		free(config_filename);
-	if (lock_file)
+	if (lock_file) {
+		unlink(lock_file);
 		free(lock_file);
+	}
 	return ret;
 }
 
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “Release config lock if the regex is invalid”
  1. Release config lock if the regex is invalidPavel Roskin, May 7, 2006
  2. Junio C HamanoMay 7, 2006
  3. Johannes SchindelinMay 8, 2006
  4. Junio C HamanoMay 8, 2006
  5. Johannes SchindelinMay 8, 2006

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.