mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-04 14:42:09 +00:00
Simplify error path in config_set
Many error paths freed their local data althought it is freed later on when the end of the function notices that there was an error. This can cause double frees and invalid memory access. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
493384e39c
commit
7a4dfd6028
15
src/config.c
15
src/config.c
@ -285,27 +285,23 @@ static int config_set(git_config *cfg, const char *name, const char *value)
|
||||
*/
|
||||
|
||||
var = git__malloc(sizeof(git_cvar));
|
||||
if(var == NULL){
|
||||
error = GIT_ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
if (var == NULL)
|
||||
return GIT_ENOMEM;
|
||||
|
||||
memset(var, 0x0, sizeof(git_cvar));
|
||||
|
||||
var->name = git__strdup(name);
|
||||
if(var->name == NULL){
|
||||
if (var->name == NULL) {
|
||||
error = GIT_ENOMEM;
|
||||
free(var);
|
||||
goto out;
|
||||
}
|
||||
|
||||
var->value = value ? git__strdup(value) : NULL;
|
||||
if (var->value == NULL && value != NULL) {
|
||||
error = GIT_ENOMEM;
|
||||
cvar_free(var);
|
||||
goto out;
|
||||
}
|
||||
|
||||
var->next = NULL;
|
||||
|
||||
CVAR_LIST_APPEND(&cfg->var_list, var);
|
||||
|
||||
out:
|
||||
@ -313,7 +309,6 @@ static int config_set(git_config *cfg, const char *name, const char *value)
|
||||
cvar_free(var);
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
int git_config_set_int(git_config *cfg, const char *name, int value)
|
||||
|
Loading…
Reference in New Issue
Block a user