]> git.ipfire.org Git - thirdparty/git.git/commitdiff
dir: fix leak when parsing "status.showUntrackedFiles"
authorPatrick Steinhardt <ps@pks.im>
Tue, 5 Nov 2024 06:17:46 +0000 (07:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Nov 2024 06:37:56 +0000 (22:37 -0800)
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>
dir.c
t/t7063-status-untracked-cache.sh

diff --git a/dir.c b/dir.c
index cb9782fa11f54c071740b0786d127dff9d34e231..7f35a3e3175355bad4f64bf4e65cf05d9bd6356f 100644 (file)
--- 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;
 
index 8929ef481f926ce8eee1414b852c3e14538afa9c..13fea7931cddef581cf4a6460aaca4c770e1d287 100755 (executable)
@@ -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