Skip to content

Commit dd98bcc

Browse files
pks-tttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent cc5b700 commit dd98bcc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,14 +2872,14 @@ static void set_untracked_ident(struct untracked_cache *uc)
28722872
static unsigned new_untracked_cache_flags(struct index_state *istate)
28732873
{
28742874
struct repository *repo = istate->repo;
2875-
char *val;
2875+
const char *val;
28762876

28772877
/*
28782878
* This logic is coordinated with the setting of these flags in
28792879
* wt-status.c#wt_status_collect_untracked(), and the evaluation
28802880
* of the config setting in commit.c#git_status_config()
28812881
*/
2882-
if (!repo_config_get_string(repo, "status.showuntrackedfiles", &val) &&
2882+
if (!repo_config_get_string_tmp(repo, "status.showuntrackedfiles", &val) &&
28832883
!strcmp(val, "all"))
28842884
return 0;
28852885

t/t7063-status-untracked-cache.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='test untracked cache'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
# On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime

0 commit comments

Comments
 (0)