Skip to content

Commit 65a1b7e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2664f2a commit 65a1b7e

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

blame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,7 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb)
29312931
void cleanup_scoreboard(struct blame_scoreboard *sb)
29322932
{
29332933
free(sb->lineno);
2934+
free(sb->final_buf);
29342935
clear_prio_queue(&sb->commits);
29352936
oidset_clear(&sb->ignore_list);
29362937

blame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct blame_scoreboard {
116116
* Used by many functions to obtain contents of the nth line,
117117
* indexed with scoreboard.lineno[blame_entry.lno].
118118
*/
119-
const char *final_buf;
119+
char *final_buf;
120120
unsigned long final_buf_size;
121121

122122
/* linked list of blames */

builtin/blame.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,6 @@ int cmd_blame(int argc,
12161216
output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);
12171217

12181218
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-
}
12251219

12261220
if (show_stats) {
12271221
printf("num read blob: %d\n", sb.num_read_blob);
@@ -1230,6 +1224,12 @@ int cmd_blame(int argc,
12301224
}
12311225

12321226
cleanup:
1227+
for (ent = sb.ent; ent; ) {
1228+
struct blame_entry *e = ent->next;
1229+
free(ent);
1230+
ent = e;
1231+
}
1232+
12331233
free(path);
12341234
cleanup_scoreboard(&sb);
12351235
release_revisions(&revs);

t/t8005-blame-i18n.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='git blame encoding conversion'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
if ! test_have_prereq ICONV

0 commit comments

Comments
 (0)