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

Re: [PATCH 2/3] read-cache: fix memory leak in do_write_index

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 21, 2017, 23:02 UTC
Message-ID
<xmqq1so45xsy.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170821212432.47364-3-kewillf@microsoft.com>
Kevin Willford <kewillf@microsoft.com> writes:
Show 6 quoted lines
> The previous_name_buf was never getting released when there
> was an error in ce_write_entry or allow was false and execution
> was returned to the caller.
>
> Signed-off-by: Kevin Willford <kewillf@microsoft.com>
> ---

Thanks for spotting an old error that dates back to at least 2013 this month. The patch looks sensible.

Show 40 quoted lines
>  read-cache.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index acfb028f48..47220cc30d 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2192,7 +2192,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
>  	int newfd = tempfile->fd;
>  	git_SHA_CTX c;
>  	struct cache_header hdr;
> -	int i, err, removed, extended, hdr_version;
> +	int i, err = 0, removed, extended, hdr_version;
>  	struct cache_entry **cache = istate->cache;
>  	int entries = istate->cache_nr;
>  	struct stat st;
> @@ -2247,15 +2247,21 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
>  			if (allow)
>  				warning(msg, ce->name);
>  			else
> -				return error(msg, ce->name);
> +				err = error(msg, ce->name);
>  
>  			drop_cache_tree = 1;
>  		}
>  		if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
> -			return -1;
> +			err = -1;
> +
> +		if (err)
> +			break;
>  	}
>  	strbuf_release(&previous_name_buf);
>  
> +	if (err)
> +		return err;
> +
>  	/* Write extension data here */
>  	if (!strip_extensions && istate->split_index) {
>  		struct strbuf sb = STRBUF_INIT;
Previous: Kevin WillfordNext: Kevin Willford
Message 4 of 6 in “read-cache: use stack ondisk struct when writing index”
  1. 0/3 read-cache: use stack ondisk struct when writing indexKevin Willford, Aug 21, 2017
  2. 1/3 perf: add test for writing the indexKevin Willford, Aug 21, 2017
  3. 2/3 read-cache: fix memory leak in do_write_indexKevin Willford, Aug 21, 2017
  4. Junio C HamanoAug 21, 2017
  5. 3/3 read-cache: avoid allocating every ondisk entry when writingKevin Willford, Aug 21, 2017
  6. Junio C HamanoAug 21, 2017

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.