Merge branch 'jk/leakfix'

Code clean-up.

* jk/leakfix:
  submodule--helper: fix leak of core.worktree value
  config: fix leak in git_config_get_expiry_in_days()
  config: drop git_config_get_string_const()
  config: fix leaks from git_config_get_string_const()
  checkout: fix leak of non-existent branch names
  submodule--helper: use strbuf_release() to free strbufs
  clear_pattern_list(): clear embedded hashmaps
This commit is contained in:
Junio C Hamano
2020-08-27 14:04:49 -07:00
17 changed files with 70 additions and 53 deletions

View File

@ -2006,18 +2006,27 @@ const struct string_list *git_configset_get_value_multi(struct config_set *cs, c
return e ? &e->value_list : NULL;
}
int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest)
int git_configset_get_string(struct config_set *cs, const char *key, char **dest)
{
const char *value;
if (!git_configset_get_value(cs, key, &value))
return git_config_string(dest, key, value);
return git_config_string((const char **)dest, key, value);
else
return 1;
}
int git_configset_get_string(struct config_set *cs, const char *key, char **dest)
int git_configset_get_string_tmp(struct config_set *cs, const char *key,
const char **dest)
{
return git_configset_get_string_const(cs, key, (const char **)dest);
const char *value;
if (!git_configset_get_value(cs, key, &value)) {
if (!value)
return config_error_nonbool(key);
*dest = value;
return 0;
} else {
return 1;
}
}
int git_configset_get_int(struct config_set *cs, const char *key, int *dest)
@ -2147,22 +2156,26 @@ const struct string_list *repo_config_get_value_multi(struct repository *repo,
return git_configset_get_value_multi(repo->config, key);
}
int repo_config_get_string_const(struct repository *repo,
const char *key, const char **dest)
int repo_config_get_string(struct repository *repo,
const char *key, char **dest)
{
int ret;
git_config_check_init(repo);
ret = git_configset_get_string_const(repo->config, key, dest);
ret = git_configset_get_string(repo->config, key, dest);
if (ret < 0)
git_die_config(key, NULL);
return ret;
}
int repo_config_get_string(struct repository *repo,
const char *key, char **dest)
int repo_config_get_string_tmp(struct repository *repo,
const char *key, const char **dest)
{
int ret;
git_config_check_init(repo);
return repo_config_get_string_const(repo, key, (const char **)dest);
ret = git_configset_get_string_tmp(repo->config, key, dest);
if (ret < 0)
git_die_config(key, NULL);
return ret;
}
int repo_config_get_int(struct repository *repo,
@ -2232,16 +2245,16 @@ const struct string_list *git_config_get_value_multi(const char *key)
return repo_config_get_value_multi(the_repository, key);
}
int git_config_get_string_const(const char *key, const char **dest)
{
return repo_config_get_string_const(the_repository, key, dest);
}
int git_config_get_string(const char *key, char **dest)
{
return repo_config_get_string(the_repository, key, dest);
}
int git_config_get_string_tmp(const char *key, const char **dest)
{
return repo_config_get_string_tmp(the_repository, key, dest);
}
int git_config_get_int(const char *key, int *dest)
{
return repo_config_get_int(the_repository, key, dest);
@ -2274,7 +2287,7 @@ int git_config_get_pathname(const char *key, const char **dest)
int git_config_get_expiry(const char *key, const char **output)
{
int ret = git_config_get_string_const(key, output);
int ret = git_config_get_string(key, (char **)output);
if (ret)
return ret;
if (strcmp(*output, "now")) {
@ -2287,11 +2300,11 @@ int git_config_get_expiry(const char *key, const char **output)
int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
{
char *expiry_string;
const char *expiry_string;
intmax_t days;
timestamp_t when;
if (git_config_get_string(key, &expiry_string))
if (git_config_get_string_tmp(key, &expiry_string))
return 1; /* no such thing */
if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {