Skip to content

Commit 8136099

Browse files
committed
Merge branch 'ss/fix-config-fd-leak' into maint
* ss/fix-config-fd-leak: config: close config file handle in case of error
2 parents dc4e7b0 + 54d160e commit 8136099

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
19541954
const char *key, const char *value,
19551955
const char *value_regex, int multi_replace)
19561956
{
1957-
int fd = -1, in_fd;
1957+
int fd = -1, in_fd = -1;
19581958
int ret;
19591959
struct lock_file *lock = NULL;
19601960
char *filename_buf = NULL;
@@ -2084,6 +2084,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
20842084
goto out_free;
20852085
}
20862086
close(in_fd);
2087+
in_fd = -1;
20872088

20882089
if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
20892090
error("chmod on %s failed: %s",
@@ -2167,6 +2168,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
21672168
free(filename_buf);
21682169
if (contents)
21692170
munmap(contents, contents_sz);
2171+
if (in_fd >= 0)
2172+
close(in_fd);
21702173
return ret;
21712174

21722175
write_err_out:

0 commit comments

Comments
 (0)