Skip to content

Commit 141766d

Browse files
pks-tgitster
authored andcommitted
line-log: fix leak when rewriting commit parents
In `process_ranges_merge_commit()` we try to figure out which of the parents can be blamed for the given line changes. When we figure out that none of the files in the line-log have changed we assign the complete blame to that commit and rewrite the parents of the current commit to only use that single parent. This is done via `commit_list_append()`, which is misleadingly _not_ appending to the list of parents. Instead, we overwrite the parents with the blamed parent. This makes us lose track of the old pointers, creating a memory leak. Fix this issue by freeing the parents before we overwrite them. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c1e98f9 commit 141766d

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

line-log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
12371237
* don't follow any other path in history
12381238
*/
12391239
add_line_range(rev, parents[i], cand[i]);
1240+
free_commit_list(commit->parents);
12401241
commit_list_append(parents[i], &commit->parents);
12411242

12421243
ret = 0;

t/t4211-line-log.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test log -L'
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
test_expect_success 'setup (import history)' '

0 commit comments

Comments
 (0)