Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
141766d1 c1e98f90

+2
+1
line-log.c
··· 1237 1237 * don't follow any other path in history 1238 1238 */ 1239 1239 add_line_range(rev, parents[i], cand[i]); 1240 + free_commit_list(commit->parents); 1240 1241 commit_list_append(parents[i], &commit->parents); 1241 1242 1242 1243 ret = 0;
+1
t/t4211-line-log.sh
··· 4 4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5 5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 6 7 + TEST_PASSES_SANITIZE_LEAK=true 7 8 . ./test-lib.sh 8 9 9 10 test_expect_success 'setup (import history)' '