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

Re: [PATCH v4 1/3] refs: keep track of unresolved reference value in iterators

From
shejialuo <shejialuo@gmail.com>
Date
Nov 23, 2024, 08:24 UTC
Message-ID
<Z0GRNGQEeoOQHKz3@ArchLinux>
In-Reply-To
<c4f5f5b7dd8dad4f17201611faee14dd1b882bff.1723217871.git.gitgitgadget@gmail.com>
On Fri, Aug 09, 2024 at 03:37:49PM +0000, John Cai via GitGitGadget wrote:
[snip]
Show 8 quoted lines
> @@ -66,6 +69,7 @@ static void free_ref_entry(struct ref_entry *entry)
>  		 */
>  		clear_ref_dir(&entry->u.subdir);
>  	}
> +	free(entry->u.value.referent);
>  	free(entry);
>  }
>  

Today, I am learning the source code of the "ref-cache.[ch]". I feel rather confused here. And I think this usage is wrong.

"free_ref_entry" will do the following things:
1. If "entry" is a directory, it will call "clear_ref_dir" which will
call "free_ref_entry" for every loose ref.
2. If "entry" is a loose ref, it will call `free(entry->u.value.referent)`
and `free(entry)`.

The problem is if "entry" is a directory, we will also execute the following statement:

    free(entry->u.value.referent);

This does not make sense. We should never access the "entry->u.value" if "entry" is a directory. So, I think the correct usage should be:

    if (entry->flag & REF_DIR) {
        ...
        clear_ref_dir(...);
    } else {
        free(entry->u.value.referent);
    }

Thanks, Jialuo

Previous: John Cai via GitGitGadgetNext: John Cai via GitGitGadget
Message 41 of 44 in “keep track of unresolved value of symbolic-ref in ref iterators”
  1. 0/4 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Jun 6, 2024
  2. 2/4 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Jun 6, 2024
  3. Jeff KingJun 11, 2024
  4. 1/4 refs: add referent parameter to refs_resolve_ref_unsafeJohn Cai via GitGitGadget, Jun 6, 2024
  5. Junio C HamanoJun 6, 2024
  6. Junio C HamanoJun 6, 2024
  7. John CaiJun 7, 2024
  8. Junio C HamanoJun 7, 2024
  9. Patrick SteinhardtJun 10, 2024
  10. Junio C HamanoJun 10, 2024
  11. John CaiJun 6, 2024
  12. Junio C HamanoJun 6, 2024
  13. Kristoffer HaugsbakkJun 28, 2024
  14. Junio C HamanoJun 28, 2024
  15. Linus ArverJun 30, 2024
  16. Junio C HamanoJun 30, 2024
  17. Jeff KingJun 11, 2024
  18. John CaiJul 30, 2024
  19. 4/4 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Jun 6, 2024
  20. 3/4 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Jun 6, 2024
  21. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 1, 2024
  22. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 1, 2024
  23. Junio C HamanoAug 1, 2024
  24. Patrick SteinhardtAug 5, 2024
  25. Junio C HamanoAug 5, 2024
  26. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 1, 2024
  27. Junio C HamanoAug 1, 2024
  28. Junio C HamanoAug 1, 2024
  29. Junio C HamanoAug 1, 2024
  30. John CaiAug 6, 2024
  31. Junio C HamanoAug 6, 2024
  32. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 1, 2024
  33. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 7, 2024
  34. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 7, 2024
  35. Junio C HamanoAug 7, 2024
  36. John CaiAug 8, 2024
  37. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 7, 2024
  38. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 7, 2024
  39. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 9, 2024
  40. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 9, 2024
  41. shejialuoNov 23, 2024
  42. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 9, 2024
  43. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 9, 2024
  44. Junio C HamanoAug 9, 2024

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.