]> git.ipfire.org Git - thirdparty/git.git/commitdiff
load_branch_decorations: fix memory leak with non-static filters
authorNicolas Guichard <nicolas@guichard.eu>
Wed, 9 Oct 2024 07:58:18 +0000 (07:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Oct 2024 17:52:44 +0000 (10:52 -0700)
load_branch_decorations calls normalize_glob_ref on each string of filter's
string_lists. This effectively replaces the potentially non-owning char* of
those items with an owning char*.

Set the strdup_string flag on those string_lists.

This was not caught until now because:
- when passing string_lists already with the strdup_string already set, the
  behaviour was correct
- when passing static string_lists, the new char* remain reachable until
  program exit

Signed-off-by: Nicolas Guichard <nicolas@guichard.eu>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
log-tree.c

index 3758e0d3b8e415f2faa5b3d01ab27e45ad644470..c65ebd2920207e8b3906fa3009df8466f133e8c8 100644 (file)
@@ -232,6 +232,11 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
                        for_each_string_list_item(item, filter->exclude_ref_config_pattern) {
                                normalize_glob_ref(item, NULL, item->string);
                        }
+
+                       /* normalize_glob_ref duplicates the strings */
+                       filter->exclude_ref_pattern->strdup_strings = 1;
+                       filter->include_ref_pattern->strdup_strings = 1;
+                       filter->exclude_ref_config_pattern->strdup_strings = 1;
                }
                decoration_loaded = 1;
                decoration_flags = flags;