mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 12:13:18 +00:00
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.
This commit is contained in:
parent
2c0cdc3a86
commit
3df9cc5922
@ -258,18 +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) {
|
||||
git_strmap_delete(b->values, var->key);
|
||||
cvar_free(var);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1018,6 +1017,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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user