config: clarify memory ownership in git_config_string()
The out parameter of `git_config_string()` is a `const char **` even though we transfer ownership of memory to the caller. This is quite misleading and has led to many memory leaks all over the place. Adapt the parameter to instead be `char **`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
83024d98f7
commit
1b261c20ed
6
config.c
6
config.c
@ -1338,7 +1338,7 @@ int git_config_bool(const char *name, const char *value)
|
||||
return v;
|
||||
}
|
||||
|
||||
int git_config_string(const char **dest, const char *var, const char *value)
|
||||
int git_config_string(char **dest, const char *var, const char *value)
|
||||
{
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
@ -1566,7 +1566,7 @@ static int git_default_core_config(const char *var, const char *value,
|
||||
|
||||
if (!strcmp(var, "core.checkroundtripencoding")) {
|
||||
FREE_AND_NULL(check_roundtrip_encoding);
|
||||
return git_config_string((const char **) &check_roundtrip_encoding, var, value);
|
||||
return git_config_string(&check_roundtrip_encoding, var, value);
|
||||
}
|
||||
|
||||
if (!strcmp(var, "core.notesref")) {
|
||||
@ -2418,7 +2418,7 @@ int git_configset_get_string(struct config_set *set, const char *key, char **des
|
||||
{
|
||||
const char *value;
|
||||
if (!git_configset_get_value(set, key, &value, NULL))
|
||||
return git_config_string((const char **)dest, key, value);
|
||||
return git_config_string(dest, key, value);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user