diff mbox series

[v2,29/29] builtin/blame: fix leaking ignore revs files

Message ID 5d7007e724b0ffaadacbe1e661d0a0ff00faa36e.1718095906.git.ps@pks.im (mailing list archive)
State Accepted
Commit fbf7a46d881429ef5495af7bbf3a6c3dacbf80b3
Headers show
Series Memory leak fixes (pt.2) | expand

Commit Message

Patrick Steinhardt June 11, 2024, 9:21 a.m. UTC
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>
 builtin/blame.c              | 3 ++-
 t/t8013-blame-ignore-revs.sh | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/builtin/blame.c b/builtin/blame.c
index 17694410ed..702fe4fb94 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -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")) {
diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh
index dbfbd86e83..d33788d867 100755
--- a/t/t8013-blame-ignore-revs.sh
+++ b/t/t8013-blame-ignore-revs.sh
@@ -1,6 +1,8 @@ 
 test_description='ignore revisions when blaming'
 . ./test-lib.sh
 # Creates: