git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] hash-object: fix descriptor leak with --literally

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 19, 2023, 06:26 UTC
Message-ID
<xmqqtu0n2g67.fsf@gitster.g>
In-Reply-To
<Y8ijpJqtkDTi792i@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> 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.
Show 10 quoted lines
> 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.
Show 15 quoted lines
>  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;
>  }
Previous: Jeff KingNext: Jeff King
Message 2 of 3 in “hash-object: fix descriptor leak with --literally”
  1. hash-object: fix descriptor leak with --literallyJeff King, Jan 19, 2023
  2. Junio C HamanoJan 19, 2023
  3. Jeff KingJan 19, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.