dir: fix leak when parsing "status.showUntrackedFiles"

We use `repo_config_get_string()` to read "status.showUntrackedFiles" from the config subsystem. This function allocates the result, but we never free the result after parsing it. The value never leaves the scope of the calling function, so refactor it to instead use `repo_config_get_string_tmp()`, which does not hand over ownership to the caller. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 5, 2024 at 07:17 UTC 813b12b6f74d75ce5ad2e7453fb763a4db44bdf8
2 files changed +3 -2
dir.c
+2 -2
@@ -2872,14 +2872,14 @@ static void set_untracked_ident(struct untracked_cache *uc)
2872 static unsigned new_untracked_cache_flags(struct index_state *istate)
2873 {
2874 struct repository *repo = istate->repo;
2875 - char *val;
2875 + const char *val;
2876
2877 /*
2878 * This logic is coordinated with the setting of these flags in
2879 * wt-status.c#wt_status_collect_untracked(), and the evaluation
2880 * of the config setting in commit.c#git_status_config()
2881 */
2882 - if (!repo_config_get_string(repo, "status.showuntrackedfiles", &val) &&
2882 + if (!repo_config_get_string_tmp(repo, "status.showuntrackedfiles", &val) &&
2883 !strcmp(val, "all"))
2884 return 0;
2885
t/t7063-status-untracked-cache.sh
+1
@@ -5,6 +5,7 @@ test_description='test untracked cache'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 # On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime