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

Re: [PATCH 3/4] unpack-trees: trivial cleanup

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 3, 2013, 17:13 UTC
Message-ID
<7vzjv7glrw.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1369922181-31016-4-git-send-email-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
> dfc has not been initialized at this point.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
Upon the first entry to this function, because dfc is 
	static struct cache_entry *dfc;

it is NULL. In that case, we allocate one instance. When the function is called again, we can reuse the entry, because it merely acts as a unique sentinel value.

And we do not free() it.
Show 17 quoted lines
>  unpack-trees.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/unpack-trees.c b/unpack-trees.c
> index ede4299..36f4ff7 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1040,8 +1040,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
>  	if (!o->skip_sparse_checkout)
>  		mark_new_skip_worktree(o->el, o->src_index, 0, CE_NEW_SKIP_WORKTREE);
>  
> -	if (!dfc)
> -		dfc = xcalloc(1, cache_entry_size(0));
> +	dfc = xcalloc(1, cache_entry_size(0));
>  	o->df_conflict_entry = dfc;
>  
>  	if (len) {
Previous: Felipe ContrerasNext: Felipe Contreras
Message 6 of 8 in “Trivial patches”
  1. 0/4 Trivial patchesFelipe Contreras, May 30, 2013
  2. 1/4 read-cache: fix wrong 'the_index' usageFelipe Contreras, May 30, 2013
  3. Junio C HamanoJun 3, 2013
  4. 2/4 read-cache: trivial style cleanupsFelipe Contreras, May 30, 2013
  5. 3/4 unpack-trees: trivial cleanupFelipe Contreras, May 30, 2013
  6. Junio C HamanoJun 3, 2013
  7. Felipe ContrerasJun 3, 2013
  8. 4/4 sha1_file: trivial style cleanupFelipe Contreras, May 30, 2013

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.