Skip to content

Commit 54d160e

Browse files
Sven Strickrothgitster
authored andcommitted
config: close config file handle in case of error
When updating an existing configuration file, we did not always close the filehandle that is reading from the current configuration file when we encountered an error (e.g. when unsetting a variable that does not exist). Signed-off-by: Sven Strickroth <email@cs-ware.de> Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e88b858 commit 54d160e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
19351935
const char *key, const char *value,
19361936
const char *value_regex, int multi_replace)
19371937
{
1938-
int fd = -1, in_fd;
1938+
int fd = -1, in_fd = -1;
19391939
int ret;
19401940
struct lock_file *lock = NULL;
19411941
char *filename_buf = NULL;
@@ -2065,6 +2065,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
20652065
goto out_free;
20662066
}
20672067
close(in_fd);
2068+
in_fd = -1;
20682069

20692070
if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
20702071
error("chmod on %s failed: %s",
@@ -2148,6 +2149,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
21482149
free(filename_buf);
21492150
if (contents)
21502151
munmap(contents, contents_sz);
2152+
if (in_fd >= 0)
2153+
close(in_fd);
21512154
return ret;
21522155

21532156
write_err_out:

0 commit comments

Comments
 (0)