Skip to content

Commit 3332f35

Browse files
pks-tgitster
authored andcommitted
builtin/blame: fix leaking prefixed paths
In `cmd_blame()` we compute prefixed paths by calling `add_prefix()`, which itself calls `prefix_path()`. While `prefix_path()` returns an allocated string, `add_prefix()` pretends to return a constant string. Consequently, this path never gets freed. Fix the return type to be `char *` and free the path to plug the memory leak. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee6a998 commit 3332f35

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

builtin/blame.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ static unsigned parse_score(const char *arg)
687687
return score;
688688
}
689689

690-
static const char *add_prefix(const char *prefix, const char *path)
690+
static char *add_prefix(const char *prefix, const char *path)
691691
{
692692
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
693693
}
@@ -865,7 +865,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
865865
int cmd_blame(int argc, const char **argv, const char *prefix)
866866
{
867867
struct rev_info revs;
868-
const char *path;
868+
char *path = NULL;
869869
struct blame_scoreboard sb;
870870
struct blame_origin *o;
871871
struct blame_entry *ent = NULL;
@@ -1226,6 +1226,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
12261226
}
12271227

12281228
cleanup:
1229+
free(path);
12291230
cleanup_scoreboard(&sb);
12301231
release_revisions(&revs);
12311232
return 0;

t/t6130-pathspec-noglob.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='test globbing (and noglob) of pathspec limiting'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'create commits with glob characters' '

t/t7010-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='setup taking and sanitizing funny paths'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success setup '

t/t8003-blame-corner-cases.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='git blame corner cases'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'

t/t8008-blame-formats.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='blame output in various formats on a simple case'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'setup' '

0 commit comments

Comments
 (0)