builtin/blame: fix leaking ignore revs files
When parsing the blame configuration we add "blame.ignoreRevsFile" configs to a string list. This string list is declared as with `NODUP`, and thus we hand over the allocated string to that list. We eventually end up calling `string_list_clear()` on that list, but due to it being declared as `NODUP` we will not release the associated strings and thus leak memory. Fix this issue by setting up the list as `DUP` instead and free the config string after insertion. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 11, 2024 at 11:21 UTC
fbf7a46d881429ef5495af7bbf3a6c3dacbf80b3
2 files changed
+4
-1
builtin/blame.c
+2
-1
@@ -67,7 +67,7 @@ static int no_whole_file_rename;
67
static int show_progress;
68
static char repeated_meta_color[COLOR_MAXLEN];
69
static int coloring_mode;
70
-static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP;
70
+static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
71
static int mark_unblamable_lines;
72
static int mark_ignored_lines;
73
@@ -725,6 +725,7 @@ static int git_blame_config(const char *var, const char *value,
725
if (ret)
726
return ret;
727
string_list_insert(&ignore_revs_file_list, str);
728
+ free(str);
729
return 0;
730
}
731
if (!strcmp(var, "blame.markunblamablelines")) {
t/t8013-blame-ignore-revs.sh
+2
@@ -1,6 +1,8 @@
1
#!/bin/sh
2
3
test_description='ignore revisions when blaming'
4
+
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./test-lib.sh
7
8
# Creates: