git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nicolas Guichard via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Nicolas Guichard <nicolas@guichard.eu>,
	Nicolas Guichard <nicolas@guichard.eu>
Subject: [PATCH v2 1/3] load_branch_decorations: fix memory leak with non-static filters
Date: Fri, 04 Oct 2024 23:22:18 +0000	[thread overview]
Message-ID: <6250a7f6d6c84654093b383744c59d3559de717b.1728084140.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1784.v2.git.git.1728084140.gitgitgadget@gmail.com>

From: Nicolas Guichard <nicolas@guichard.eu>

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>
---
 log-tree.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/log-tree.c b/log-tree.c
index 3758e0d3b8e..cd57de2424e 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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 = true;
+			filter->include_ref_pattern->strdup_strings = true;
+			filter->exclude_ref_config_pattern->strdup_strings = true;
 		}
 		decoration_loaded = 1;
 		decoration_flags = flags;
-- 
gitgitgadget


  reply	other threads:[~2024-10-04 23:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-21 18:37 [PATCH 0/2] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-09-21 18:37 ` [PATCH 1/2] sequencer.c: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-09-23 19:32   ` Junio C Hamano
2024-09-21 18:38 ` [PATCH 2/2] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-09-23 19:38   ` Junio C Hamano
2024-10-04 23:22 ` [PATCH v2 0/3] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-10-04 23:22   ` Nicolas Guichard via GitGitGadget [this message]
2024-10-05  3:43     ` [PATCH v2 1/3] load_branch_decorations: fix memory leak with non-static filters Eric Sunshine
2024-10-04 23:22   ` [PATCH v2 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-05  3:44     ` Eric Sunshine
2024-10-04 23:22   ` [PATCH v2 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09  7:58   ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 1/3] load_branch_decorations: fix memory leak with non-static filters Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09 14:21       ` Phillip Wood
2024-10-09 17:57         ` Junio C Hamano
2024-10-09 14:22     ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6250a7f6d6c84654093b383744c59d3559de717b.1728084140.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nicolas@guichard.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).