Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:42:25
Subsystem: the rest · Maintainer: Linus Torvalds

Hi,

On Sun, 7 May 2006, Pavel Roskin wrote:
quoted hunk ↗ jump to hunk
@@ -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;
 }
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help