Git fork

builtin/blame: fix leaking blame entries with `--incremental`

When passing `--incremental` to git-blame(1) we exit early by jumping to
the `cleanup` label. But some of the cleanups we perform are handled
between the `goto` and its label, and thus we leak the data.

Move the cleanups after the `cleanup` label. While at it, move the logic
to free the scoreboard's `final_buf` into `cleanup_scoreboard()` and
drop its `const` declaration.

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
65a1b7e2 2664f2a0

+10 -7
+1
blame.c
··· 2931 2931 void cleanup_scoreboard(struct blame_scoreboard *sb) 2932 2932 { 2933 2933 free(sb->lineno); 2934 + free(sb->final_buf); 2934 2935 clear_prio_queue(&sb->commits); 2935 2936 oidset_clear(&sb->ignore_list); 2936 2937
+1 -1
blame.h
··· 116 116 * Used by many functions to obtain contents of the nth line, 117 117 * indexed with scoreboard.lineno[blame_entry.lno]. 118 118 */ 119 - const char *final_buf; 119 + char *final_buf; 120 120 unsigned long final_buf_size; 121 121 122 122 /* linked list of blames */
+6 -6
builtin/blame.c
··· 1216 1216 output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR); 1217 1217 1218 1218 output(&sb, output_option); 1219 - free((void *)sb.final_buf); 1220 - for (ent = sb.ent; ent; ) { 1221 - struct blame_entry *e = ent->next; 1222 - free(ent); 1223 - ent = e; 1224 - } 1225 1219 1226 1220 if (show_stats) { 1227 1221 printf("num read blob: %d\n", sb.num_read_blob); ··· 1230 1224 } 1231 1225 1232 1226 cleanup: 1227 + for (ent = sb.ent; ent; ) { 1228 + struct blame_entry *e = ent->next; 1229 + free(ent); 1230 + ent = e; 1231 + } 1232 + 1233 1233 free(path); 1234 1234 cleanup_scoreboard(&sb); 1235 1235 release_revisions(&revs);
+2
t/t8005-blame-i18n.sh
··· 1 1 #!/bin/sh 2 2 3 3 test_description='git blame encoding conversion' 4 + 5 + TEST_PASSES_SANITIZE_LEAK=true 4 6 . ./test-lib.sh 5 7 6 8 if ! test_have_prereq ICONV