summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-05-28 07:54:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-28 18:32:04 (GMT)
commit3a1b3126ed5a0b51d5b1fdba827c92bf2acf5fc6 (patch)
tree1818bbab5184b0774adb19b3fc6606e07f0d3256 /config.c
parenta1293ef7c3690829a6ac47fc45f3f26b96b5c9f5 (diff)
downloadgit-3a1b3126ed5a0b51d5b1fdba827c92bf2acf5fc6.zip
git-3a1b3126ed5a0b51d5b1fdba827c92bf2acf5fc6.tar.gz
git-3a1b3126ed5a0b51d5b1fdba827c92bf2acf5fc6.tar.bz2
config.c: fix mmap leak when writing config
We mmap the existing config file, but fail to unmap it if we hit an error. The function already has a shared exit path, so we can fix this by moving the mmap pointer to the function scope and clearing it in the shared exit. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/config.c b/config.c
index 752e2e2..dc7f8b2 100644
--- a/config.c
+++ b/config.c
@@ -1934,6 +1934,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
int ret;
struct lock_file *lock = NULL;
char *filename_buf = NULL;
+ char *contents = NULL;
+ size_t contents_sz;
/* parse-key returns negative; flip the sign to feed exit(3) */
ret = 0 - git_config_parse_key(key, &store.key, &store.baselen);
@@ -1983,8 +1985,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
goto write_err_out;
} else {
struct stat st;
- char *contents;
- size_t contents_sz, copy_begin, copy_end;
+ size_t copy_begin, copy_end;
int i, new_line = 0;
if (value_regex == NULL)
@@ -2103,8 +2104,6 @@ int git_config_set_multivar_in_file(const char *config_filename,
contents_sz - copy_begin) <
contents_sz - copy_begin)
goto write_err_out;
-
- munmap(contents, contents_sz);
}
if (commit_lock_file(lock) < 0) {
@@ -2130,6 +2129,8 @@ out_free:
if (lock)
rollback_lock_file(lock);
free(filename_buf);
+ if (contents)
+ munmap(contents, contents_sz);
return ret;
write_err_out: