From: Jeff King <peff@peff.net>
To: Elijah Newren <newren@gmail.com>
Cc: "Michal Koutný" <mkoutny@suse.com>,
git@vger.kernel.org, "Jean Delvare" <jdelvare@suse.de>,
"Usman Akinyemi" <usmanakinyemi202@gmail.com>,
"Taylor Blau" <me@ttaylorr.com>,
"Junio C Hamano" <gitster@pobox.com>,
"René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH v2 2/3] merge-ll: catch close() errors when writing external tempfiles
Date: Mon, 14 Sep 2026 12:56:54 -0400 [thread overview]
Message-ID: <20260914165654.GB32247@peff.net> (raw)
In-Reply-To: <CABPp-BG6wYkr4wjr-iqak9fYo4+49WvjROdZ_MK5=g27WcUmMA@mail.gmail.com>
On Fri, Sep 11, 2026 at 11:06:43AM -0700, Elijah Newren wrote:
> > - if (write_in_full(fd, src->ptr, src->size) < 0)
> > + if (write_in_full(fd, src->ptr, src->size) < 0 ||
> > + close(fd) < 0)
> > die_errno("unable to write temp-file");
> > - close(fd);
> > }
>
> I got tripped up at first on this patch; if write_in_full() < 0, then
> we won't explicitly close(), but since die will result in an implicit
> close, that's not a problem.
>
> Instead, the only thing that changes is we also die if close() fails.
Yeah, this is a subtle mistake that we've had to fix before. Doing:
if (write_in_full(fd, ...) || close(fd))
return error(...);
is a hard-to-spot leak. It's not present here because we're calling
die() instead of returning, but maybe it is worth writing it out to set
a good example, like:
if (write_in_full(...))
die_errno("unable to write");
if (close(...))
die_errno("unable to close");
Since I'm re-rolling anyway.
-Peff
next prev parent reply other threads:[~2026-09-14 16:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 15:06 [PATCH] merge-ll: Cleanup merge driver temporaries after interrupt Michal Koutný
2026-09-10 16:22 ` Jeff King
2026-09-11 14:43 ` Michal Koutný
2026-09-11 17:10 ` [PATCH v2 0/3] merge-ll: Cleanup merge driver temporaries after Jeff King
2026-09-11 17:11 ` [PATCH v2 1/3] merge-ll: use strbuf to read back external merge result Jeff King
2026-09-11 18:06 ` Elijah Newren
2026-09-11 18:32 ` Junio C Hamano
2026-09-14 16:53 ` Jeff King
2026-09-11 17:11 ` [PATCH v2 2/3] merge-ll: catch close() errors when writing external tempfiles Jeff King
2026-09-11 18:06 ` Elijah Newren
2026-09-14 16:56 ` Jeff King [this message]
2026-09-11 17:13 ` [PATCH v2 3/3] merge-ll: use tempfile API for external driver files Jeff King
2026-09-11 18:10 ` Elijah Newren
2026-09-14 13:24 ` Michal Koutný
2026-09-14 16:57 ` Jeff King
2026-09-14 13:23 ` [PATCH v2 0/3] merge-ll: Cleanup merge driver temporaries after Michal Koutný
2026-09-14 16:59 ` Jeff King
2026-09-29 5:12 ` [PATCH v3 0/2] merge-ll: Cleanup merge driver temporaries after signal Jeff King
2026-09-29 5:12 ` [PATCH v3 1/2] merge-ll: catch close() errors when writing external tempfiles Jeff King
2026-09-29 5:13 ` [PATCH v3 2/2] merge-ll: use tempfile API for external driver files Jeff King
2026-09-29 16:51 ` Junio C Hamano
2026-09-29 18:25 ` Jeff King
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=20260914165654.GB32247@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jdelvare@suse.de \
--cc=l.s.r@web.de \
--cc=me@ttaylorr.com \
--cc=mkoutny@suse.com \
--cc=newren@gmail.com \
--cc=usmanakinyemi202@gmail.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