summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-26 15:45:30 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-26 15:45:30 -0700
commit51e83a4898b47ff3286f1cff65c3715ee803ade9 (patch)
tree4738180b1e465bff1e666e38274fee15eb18c8de /config.c
parent33f2c4ff7b9ac02cd9010d504e847b912b35baf6 (diff)
parent54d160ec0deebfa7bf0cfc499c69ff5364b118c6 (diff)
downloadgit-51e83a4898b47ff3286f1cff65c3715ee803ade9.tar.gz
Merge branch 'ss/fix-config-fd-leak'
* ss/fix-config-fd-leak: config: close config file handle in case of error
Diffstat (limited to 'config.c')
-rw-r--r--config.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/config.c b/config.c
index a34b850cdc..c027e6fbe0 100644
--- a/config.c
+++ b/config.c
@@ -1935,7 +1935,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
const char *key, const char *value,
const char *value_regex, int multi_replace)
{
- int fd = -1, in_fd;
+ int fd = -1, in_fd = -1;
int ret;
struct lock_file *lock = NULL;
char *filename_buf = NULL;
@@ -2065,6 +2065,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
goto out_free;
}
close(in_fd);
+ in_fd = -1;
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
error("chmod on %s failed: %s",
@@ -2148,6 +2149,8 @@ out_free:
free(filename_buf);
if (contents)
munmap(contents, contents_sz);
+ if (in_fd >= 0)
+ close(in_fd);
return ret;
write_err_out: