From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] hash-object: fix descriptor leak with --literally
Date: Wed, 18 Jan 2023 22:26:40 -0800 [thread overview]
Message-ID: <xmqqtu0n2g67.fsf@gitster.g> (raw)
In-Reply-To: <Y8ijpJqtkDTi792i@coredump.intra.peff.net> (Jeff King's message of "Wed, 18 Jan 2023 20:57:56 -0500")
Jeff King <peff@peff.net> writes:
> In hash_object(), we open a descriptor for each file to hash (whether we
> got the filename from the command line or --stdin-paths), but never
> close it. For the traditional code path which feeds the result to
> index_fd(), this is OK; it closes the descriptor for us.
>
> But 5ba9a93b39 (hash-object: add --literally option, 2014-09-11) a
> second code path which does not close the descriptor.
A sentence without verb? "5ba9 (hash-...) added a second code path,
which does not close the descriptor." or something?
> After this patch, it completes successfully. I didn't bother with a
> test, as it's a pain to deal with descriptor limits portably, and the
> fix is so trivial.
True. Will queue. Thanks.
> I do think the world would be less confusing if index_fd() didn't close
> the descriptor we pass it, and then hash_file() could just do:
>
> fd = open();
> hash_fd(fd);
> close(fd);
>
> which is much more readable. But it has many other callers. So even if
> we wanted to untangle all that, I think it makes sense to do this
> obvious fix in the meantime.
Indeed, thanks.
> builtin/hash-object.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/builtin/hash-object.c b/builtin/hash-object.c
> index b506381502..44db83f07f 100644
> --- a/builtin/hash-object.c
> +++ b/builtin/hash-object.c
> @@ -27,6 +27,7 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig
> else
> ret = write_object_file_literally(buf.buf, buf.len, type, oid,
> flags);
> + close(fd);
> strbuf_release(&buf);
> return ret;
> }
next prev parent reply other threads:[~2023-01-19 6:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 1:57 [PATCH] hash-object: fix descriptor leak with --literally Jeff King
2023-01-19 6:26 ` Junio C Hamano [this message]
2023-01-19 8:20 ` 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=xmqqtu0n2g67.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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.