All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Alex Henrie <alexhenrie24@gmail.com>
Cc: git@vger.kernel.org, paulus@ozlabs.org
Subject: Re: [PATCH 1/3] log: fix memory leak if --graph is passed multiple times
Date: Wed, 09 Feb 2022 10:16:04 -0800	[thread overview]
Message-ID: <xmqqh7979a8r.fsf@gitster.g> (raw)
In-Reply-To: <20220209162350.169971-1-alexhenrie24@gmail.com> (Alex Henrie's message of "Wed, 9 Feb 2022 09:23:47 -0700")

Alex Henrie <alexhenrie24@gmail.com> writes:

> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
>  revision.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/revision.c b/revision.c
> index ad4286fbdd..c03c387edd 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2424,9 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
>  		revs->pretty_given = 1;
>  		revs->abbrev_commit = 1;
>  	} else if (!strcmp(arg, "--graph")) {
> -		revs->topo_order = 1;
> -		revs->rewrite_parents = 1;
> -		revs->graph = graph_init(revs);
> +		if (!revs->graph) {
> +			revs->topo_order = 1;
> +			revs->rewrite_parents = 1;
> +			revs->graph = graph_init(revs);
> +		}

I understand the refs->graph part but are there ways to turn off
topo_order or rewrite_parents with _other_ options?  I.e.

    git log --graph --another-option --graph

if --another-option flips either bits off, would make the graph
code misbehave because it requires both of these bits set.

I think this is safe in the corrent code, simply because there do
not seem to be a way to unset these bits once they are set, but
I am not sure if that is something we want to rely on.

I think an ideal endgame should look more like

	} else if (!strcmp(arg, "--graph")) {
		revs->topo_order = 1;
		revs->rewrite_parents = 1;
+		graph_clear(revs->graph);
		revs->graph = graph_init(revs);

where graph_clear() is to release the resource held by the git_graph
struct that was previously prepared (and possibly used), and becomes
a no-op when given NULL (just like free(NULL) is OK).

But if we want to punt on introducing graph_clear(), perhaps

	} else if (!strcmp(arg, "--graph")) {
		revs->topo_order = 1;
		revs->rewrite_parents = 1;
		if (!revs->graph)
			revs->graph = graph_init(revs);

would be closer to the ideal endgame (and have an in-code comment to
hint future developers that (1) we are aware that this is not ideal,
and that (2) the right way is to clear the previously allocated one
before doing another init).

Thanks.

>  	} else if (!strcmp(arg, "--encode-email-headers")) {
>  		revs->encode_email_headers = 1;
>  	} else if (!strcmp(arg, "--no-encode-email-headers")) {

      parent reply	other threads:[~2022-02-09 18:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 16:23 [PATCH 1/3] log: fix memory leak if --graph is passed multiple times Alex Henrie
2022-02-09 16:23 ` [PATCH 2/3] log: add a config option for --graph Alex Henrie
2022-02-09 18:25   ` Junio C Hamano
2022-02-10 16:49     ` Alex Henrie
2022-02-09 16:23 ` [PATCH 3/3] gitk: set log.graph=false when running `git log` Alex Henrie
2022-02-09 18:26   ` Junio C Hamano
2022-02-10 16:50     ` Alex Henrie
2022-02-10 20:15       ` Junio C Hamano
2022-02-09 18:16 ` Junio C Hamano [this message]

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=xmqqh7979a8r.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=alexhenrie24@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=paulus@ozlabs.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.