Skip to content

Commit 66eede4

Browse files
peffgitster
authored andcommitted
prepare_repo_settings(): plug leak of config values
We call repo_config_get_string() for fetch.negotiationAlgorithm, which allocates a copy of the string, but we never free it. We could add a call to free(), but there's an even simpler solution: we don't need the string to persist beyond a few strcasecmp() calls, so we can instead use the "_tmp" variant which gives us a const pointer to the cached value. We need to switch the type of "strval" to "const char *" for this to work, which affects a similar call that checks core.untrackedCache. But it's in the same boat! It doesn't actually need the value to persist beyond a maybe_bool() check (though it does remember to correctly free the string afterwards). So we can simplify it at the same time. Note that this core.untrackedCache check arguably should be using repo_config_get_maybe_bool(), but there are some subtle behavior changes. E.g., it doesn't currently allow a value-less "true". Arguably it should, but let's avoid lumping further changes in what should be a simple leak cleanup. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e2619d commit 66eede4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

repo-settings.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void prepare_repo_settings(struct repository *r)
1515
{
1616
int experimental;
1717
int value;
18-
char *strval;
18+
const char *strval;
1919
int manyfiles;
2020

2121
if (!r->gitdir)
@@ -67,7 +67,7 @@ void prepare_repo_settings(struct repository *r)
6767
if (!repo_config_get_int(r, "index.version", &value))
6868
r->settings.index_version = value;
6969

70-
if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
70+
if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
7171
int v = git_parse_maybe_bool(strval);
7272

7373
/*
@@ -78,10 +78,9 @@ void prepare_repo_settings(struct repository *r)
7878
if (v >= 0)
7979
r->settings.core_untracked_cache = v ?
8080
UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
81-
free(strval);
8281
}
8382

84-
if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
83+
if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
8584
int fetch_default = r->settings.fetch_negotiation_algorithm;
8685
if (!strcasecmp(strval, "skipping"))
8786
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;

0 commit comments

Comments
 (0)