Skip to content

Commit 51e83a4

Browse files
committed
Merge branch 'ss/fix-config-fd-leak'
* ss/fix-config-fd-leak: config: close config file handle in case of error
2 parents 33f2c4f + 54d160e commit 51e83a4

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
@@ -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(get_lock_file_path(lock), 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)