aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-11-05 07:17:46 +0100
committerJunio C Hamano <gitster@pobox.com>2024-11-04 22:37:56 -0800
commit813b12b6f74d75ce5ad2e7453fb763a4db44bdf8 (patch)
tree5bcaa05ac595808a8597e7055ba8906310c349cd
parent0bc0fcf0b27271722de4fac668658ad5318bec84 (diff)
downloadgit-813b12b6f74d75ce5ad2e7453fb763a4db44bdf8.tar.gz
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>
-rw-r--r--dir.c4
-rwxr-xr-xt/t7063-status-untracked-cache.sh1
2 files changed, 3 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index cb9782fa11..7f35a3e317 100644
--- a/dir.c
+++ b/dir.c
@@ -2872,14 +2872,14 @@ static void set_untracked_ident(struct untracked_cache *uc)
static unsigned new_untracked_cache_flags(struct index_state *istate)
{
struct repository *repo = istate->repo;
- char *val;
+ const char *val;
/*
* This logic is coordinated with the setting of these flags in
* wt-status.c#wt_status_collect_untracked(), and the evaluation
* of the config setting in commit.c#git_status_config()
*/
- if (!repo_config_get_string(repo, "status.showuntrackedfiles", &val) &&
+ if (!repo_config_get_string_tmp(repo, "status.showuntrackedfiles", &val) &&
!strcmp(val, "all"))
return 0;
diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 8929ef481f..13fea7931c 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -5,6 +5,7 @@ test_description='test untracked cache'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime