git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] am: plug FILE * leak in split_mail_conv()
Date: Thu, 12 May 2016 00:47:30 -0400	[thread overview]
Message-ID: <20160512044730.GA5436@sigill.intra.peff.net> (raw)
In-Reply-To: <20160511233546.13090-2-gitster@pobox.com>

On Wed, May 11, 2016 at 04:35:46PM -0700, Junio C Hamano wrote:

> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/am.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/am.c b/builtin/am.c
> index f1a84c6..a373928 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -761,9 +761,11 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
>  		mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
>  
>  		out = fopen(mail, "w");
> -		if (!out)
> +		if (!out) {
> +			fclose(in);
>  			return error(_("could not open '%s' for writing: %s"),
>  					mail, strerror(errno));
> +		}

Presumably `fclose` doesn't ever overwrite errno in practice, but I
guess it could in theory.

I also found it weird that we might fclose(stdin) via this line, but
that matches what happens in the non-error path, so I guess it's OK?

-Peff

  reply	other threads:[~2016-05-12  4:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 23:35 [PATCH 1/2] am: plug small memory leak when split_mail_stgit_series() fails Junio C Hamano
2016-05-11 23:35 ` [PATCH 2/2] am: plug FILE * leak in split_mail_conv() Junio C Hamano
2016-05-12  4:47   ` Jeff King [this message]
2016-05-12  5:23     ` Mikael Magnusson
2016-05-12  5:29       ` Jeff King
2016-05-12  7:59     ` Eric Wong
2016-05-12  8:03       ` Jeff King
2016-05-12 15:59     ` Junio C Hamano

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=20160512044730.GA5436@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).