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
20
remote.c
20
remote.c
@ -428,29 +428,29 @@ static int handle_config(const char *key, const char *value,
|
||||
else if (!strcmp(subkey, "prunetags"))
|
||||
remote->prune_tags = git_config_bool(key, value);
|
||||
else if (!strcmp(subkey, "url")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
add_url(remote, v);
|
||||
} else if (!strcmp(subkey, "pushurl")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
add_pushurl(remote, v);
|
||||
} else if (!strcmp(subkey, "push")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
refspec_append(&remote->push, v);
|
||||
free((char *)v);
|
||||
free(v);
|
||||
} else if (!strcmp(subkey, "fetch")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
refspec_append(&remote->fetch, v);
|
||||
free((char *)v);
|
||||
free(v);
|
||||
} else if (!strcmp(subkey, "receivepack")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
if (!remote->receivepack)
|
||||
@ -458,7 +458,7 @@ static int handle_config(const char *key, const char *value,
|
||||
else
|
||||
error(_("more than one receivepack given, using the first"));
|
||||
} else if (!strcmp(subkey, "uploadpack")) {
|
||||
const char *v;
|
||||
char *v;
|
||||
if (git_config_string(&v, key, value))
|
||||
return -1;
|
||||
if (!remote->uploadpack)
|
||||
@ -471,10 +471,10 @@ static int handle_config(const char *key, const char *value,
|
||||
else if (!strcmp(value, "--tags"))
|
||||
remote->fetch_tags = 2;
|
||||
} else if (!strcmp(subkey, "proxy")) {
|
||||
return git_config_string((const char **)&remote->http_proxy,
|
||||
return git_config_string(&remote->http_proxy,
|
||||
key, value);
|
||||
} else if (!strcmp(subkey, "proxyauthmethod")) {
|
||||
return git_config_string((const char **)&remote->http_proxy_authmethod,
|
||||
return git_config_string(&remote->http_proxy_authmethod,
|
||||
key, value);
|
||||
} else if (!strcmp(subkey, "vcs")) {
|
||||
return git_config_string(&remote->foreign_vcs, key, value);
|
||||
|
Reference in New Issue
Block a user