git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] apply: don't leak fd on fdopen() error
Date: Fri, 05 Apr 2024 10:09:12 -0700	[thread overview]
Message-ID: <xmqqv84vvirr.fsf@gitster.g> (raw)
In-Reply-To: <5ba55ee4-94c7-4094-a744-584fc623b391@web.de> ("René Scharfe"'s message of "Fri, 5 Apr 2024 12:58:16 +0200")

René Scharfe <l.s.r@web.de> writes:

> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  apply.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index 432837a674..1cfbc2f074 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -4655,8 +4655,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
>  			return error_errno(_("cannot open %s"), namebuf);
>  	}
>  	rej = fdopen(fd, "w");
> -	if (!rej)
> -		return error_errno(_("cannot open %s"), namebuf);
> +	if (!rej) {
> +		error_errno(_("cannot open %s"), namebuf);
> +		close(fd);
> +		return -1;
> +	}

Ah, true, this fd is what we created in this function, and we should
close it.  Well spotted.

Will queue.

>
>  	/* Normal git tools never deal with .rej, so do not pretend
>  	 * this is a git patch by saying --git or giving extended
> --
> 2.44.0


      reply	other threads:[~2024-04-05 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 10:58 [PATCH] apply: don't leak fd on fdopen() error René Scharfe
2024-04-05 17:09 ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqv84vvirr.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).