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

Re: [PATCHv4 3/4] bundle: don't leak an fd in case of early return

From
Jeff King <peff@peff.net>
Date
Apr 1, 2016, 17:31 UTC
Message-ID
<20160401173109.GA21061@sigill.intra.peff.net>
In-Reply-To
<xmqqk2khi6eo.fsf@gitster.mtv.corp.google.com>
On Fri, Apr 01, 2016 at 10:29:51AM -0700, Junio C Hamano wrote:
Show 32 quoted lines
> > This does still suffer from the double-close I mentioned earlier. I'm
> > not sure if we want to address that or not.
> 
> Something like this on top?
> 
>  bundle.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/bundle.c b/bundle.c
> index 08e32ca..bbf4efa 100644
> --- a/bundle.c
> +++ b/bundle.c
> @@ -453,8 +453,10 @@ int create_bundle(struct bundle_header *header, const char *path,
>  		goto err;
>  
>  	/* write pack */
> -	if (write_pack_data(bundle_fd, &revs))
> +	if (write_pack_data(bundle_fd, &revs)) {
> +		bundle_fd = -1; /* already closed by the above call */
>  		goto err;
> +	}
>  
>  	if (!bundle_to_stdout) {
>  		if (commit_lock_file(&lock))
> @@ -463,7 +465,8 @@ int create_bundle(struct bundle_header *header, const char *path,
>  	return 0;
>  err:
>  	if (!bundle_to_stdout) {
> -		close(bundle_fd);
> +		if (0 <= bundle_fd)
> +			close(bundle_fd);
>  		rollback_lock_file(&lock);
Yep, that looks fine.
-Peff
Previous: Junio C HamanoNext: Stefan Beller
Message 13 of 14 in “[PATCHv4 0/4] Some cleanups”
  1. Stefan BellerApr 1, 2016
  2. 1/4 notes: don't leak memory in git_config_get_notes_strategyStefan Beller, Apr 1, 2016
  3. Eric SunshineApr 1, 2016
  4. Junio C HamanoApr 1, 2016
  5. Junio C HamanoApr 1, 2016
  6. Jeff KingApr 1, 2016
  7. Eric SunshineApr 1, 2016
  8. 2/4 abbrev_sha1_in_line: don't leak memoryStefan Beller, Apr 1, 2016
  9. 3/4 bundle: don't leak an fd in case of early returnStefan Beller, Apr 1, 2016
  10. Junio C HamanoApr 1, 2016
  11. Jeff KingApr 1, 2016
  12. Junio C HamanoApr 1, 2016
  13. Jeff KingApr 1, 2016
  14. 4/4 credential-cache, send_request: close fd when doneStefan Beller, Apr 1, 2016

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.