aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-11-20 14:39:30 +0100
committerJunio C Hamano <gitster@pobox.com>2024-11-21 08:23:40 +0900
commit65a1b7e2bdbdff523f8d55e0036bfad72467bfc8 (patch)
tree7fe0fed86411935b4f431472a4bc7f78af571356
parent2664f2a0cb18369253acadfa3cb43b1cbf0ae067 (diff)
downloadgit-65a1b7e2bdbdff523f8d55e0036bfad72467bfc8.tar.xz
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>
-rw-r--r--blame.c1
-rw-r--r--blame.h2
-rw-r--r--builtin/blame.c12
-rwxr-xr-xt/t8005-blame-i18n.sh2
4 files changed, 10 insertions, 7 deletions
diff --git a/blame.c b/blame.c
index 90633380cd..bf69768a7d 100644
--- a/blame.c
+++ b/blame.c
@@ -2931,6 +2931,7 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb)
void cleanup_scoreboard(struct blame_scoreboard *sb)
{
free(sb->lineno);
+ free(sb->final_buf);
clear_prio_queue(&sb->commits);
oidset_clear(&sb->ignore_list);
diff --git a/blame.h b/blame.h
index 5b4e47d44c..3b34be0e5c 100644
--- a/blame.h
+++ b/blame.h
@@ -116,7 +116,7 @@ struct blame_scoreboard {
* Used by many functions to obtain contents of the nth line,
* indexed with scoreboard.lineno[blame_entry.lno].
*/
- const char *final_buf;
+ char *final_buf;
unsigned long final_buf_size;
/* linked list of blames */
diff --git a/builtin/blame.c b/builtin/blame.c
index e407a22da3..6a7bb3b072 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1216,12 +1216,6 @@ parse_done:
output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);
output(&sb, output_option);
- free((void *)sb.final_buf);
- for (ent = sb.ent; ent; ) {
- struct blame_entry *e = ent->next;
- free(ent);
- ent = e;
- }
if (show_stats) {
printf("num read blob: %d\n", sb.num_read_blob);
@@ -1230,6 +1224,12 @@ parse_done:
}
cleanup:
+ for (ent = sb.ent; ent; ) {
+ struct blame_entry *e = ent->next;
+ free(ent);
+ ent = e;
+ }
+
free(path);
cleanup_scoreboard(&sb);
release_revisions(&revs);
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
index 7a1f581c24..fa765aff99 100755
--- a/t/t8005-blame-i18n.sh
+++ b/t/t8005-blame-i18n.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='git blame encoding conversion'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
if ! test_have_prereq ICONV