From f0dccfe6c961792b44d7cc9c05a9a5932d5ea13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 3 May 2012 16:07:22 +0200 Subject: config: don't use freed memory on error Change the order and set a NULL so we don't try to access freed memory in case of an error. --- src/config_file.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/config_file.c') diff --git a/src/config_file.c b/src/config_file.c index be0977475..3219cca5c 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -258,17 +258,17 @@ static int config_set(git_config_file *cfg, const char *name, const char *value) GITERR_CHECK_ALLOC(var->value); } + if (config_write(b, key, NULL, value) < 0) { + cvar_free(var); + return -1; + } + git_strmap_insert2(b->values, key, var, old_var, rval); if (rval < 0) return -1; if (old_var != NULL) cvar_free(old_var); - if (config_write(b, key, NULL, value) < 0) { - cvar_free(var); - return -1; - } - return 0; } @@ -1021,6 +1021,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p pre_end = post_start = cfg->reader.read_ptr; git__free(current_section); + current_section = NULL; if (parse_section_header(cfg, ¤t_section) < 0) goto rewrite_fail; -- cgit v1.2.1