public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: git@vger•kernel.org
Subject: Re: [PATCH] fmt-merge-msg: plug small leak of commit buffer
Date: Mon, 20 Apr 2015 14:35:28 -0700	[thread overview]
Message-ID: <xmqqoamijxen.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20150415221431.GA27566@peff.net> (Jeff King's message of "Wed, 15 Apr 2015 18:14:32 -0400")

Jeff King <peff@peff•net> writes:

> I note that record_person does not seem to care about the commit at all,
> so an alternative fix would be:
>
> diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
> index 1d962dc..9f0e608 100644
> --- a/builtin/fmt-merge-msg.c
> +++ b/builtin/fmt-merge-msg.c
> @@ -223,16 +223,14 @@ static void add_branch_desc(struct strbuf *out, const char *name)
>  
>  #define util_as_integral(elem) ((intptr_t)((elem)->util))
>  
> -static void record_person(int which, struct string_list *people,
> -			  struct commit *commit)
> +static void record_person_from_buf(int which, struct string_list *people,
> +				   const char *buffer)
>  {
> -	const char *buffer;
>  	char *name_buf, *name, *name_end;
>  	struct string_list_item *elem;
>  	const char *field;
>  
>  	field = (which == 'a') ? "\nauthor " : "\ncommitter ";
> -	buffer = get_commit_buffer(commit, NULL);
>  	name = strstr(buffer, field);
>  	if (!name)
>  		return;
> @@ -245,7 +243,6 @@ static void record_person(int which, struct string_list *people,
>  	if (name_end < name)
>  		return;
>  	name_buf = xmemdupz(name, name_end - name + 1);
> -	unuse_commit_buffer(commit, buffer);
>  
>  	elem = string_list_lookup(people, name_buf);
>  	if (!elem) {
> @@ -256,6 +253,14 @@ static void record_person(int which, struct string_list *people,
>  	free(name_buf);
>  }
>  
> +static void record_person(int which, struct string_list *people,
> +			  struct commit *commit)
> +{
> +	const char *buf = get_commit_buffer(commit, NULL);
> +	record_person_from_buf(which, people, buf);
> +	unuse_commit_buffer(commit, buf);
> +}
> +
>  static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
>  {
>  	const struct string_list_item *a = a_, *b = b_;
>
>
> This has the slight advantage that it adapts naturally if record_person
> grows more exits, but I don't think it is a big deal either way (it only
> matters if the new exit fails to copy the surrounding code and use "goto
> leave").

Yeah, let me steal that from you.

Thanks.

      reply	other threads:[~2015-04-20 21:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15 21:25 [PATCH] fmt-merge-msg: plug small leak of commit buffer Junio C Hamano
2015-04-15 21:30 ` Junio C Hamano
2015-04-15 22:14   ` Jeff King
2015-04-20 21:35     ` 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=xmqqoamijxen.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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