]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/blame: fix leaking ignore revs files
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:21:29 +0000 (11:21 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:08 +0000 (13:15 -0700)
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>
builtin/blame.c
t/t8013-blame-ignore-revs.sh

index 17694410ed900e035ef89003b48f0d9a80886196..702fe4fb94c731d46623092acef528c6261fb451 100644 (file)
@@ -67,7 +67,7 @@ static int no_whole_file_rename;
 static int show_progress;
 static char repeated_meta_color[COLOR_MAXLEN];
 static int coloring_mode;
-static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP;
+static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
 static int mark_unblamable_lines;
 static int mark_ignored_lines;
 
@@ -725,6 +725,7 @@ static int git_blame_config(const char *var, const char *value,
                if (ret)
                        return ret;
                string_list_insert(&ignore_revs_file_list, str);
+               free(str);
                return 0;
        }
        if (!strcmp(var, "blame.markunblamablelines")) {
index dbfbd86e83a756b1155925d3b739a6396d86af3c..d33788d86772936a4e1ad0a1acbca9b2d9b57662 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='ignore revisions when blaming'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # Creates: