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

Re: [PATCH] remote.c: make match_refs() copy src ref before assigning to peer_ref

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 24, 2009, 06:53 UTC
Message-ID
<76718490902232253o4c7667d9h43f06d81794cef60@mail.gmail.com>
In-Reply-To
<7vfxi4mk8n.fsf@gitster.siamese.dyndns.org>
On Tue, Feb 24, 2009 at 1:17 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> This issue has gone undetected as the existing callers of match_heads()
>> call it only once and then terminate, w/o ever bothering to free the src
>> or dst lists.
>
> Thanks.
>
> It sounds more like existing function and usage was alright but your new
> caller made it into an issue.

Well, maybe. The existing function alters the passed in dst argument (a ref list) in two ways:

1) It potentially adds new refs to the tail of the list.
2) For the existing and new refs, it populates their peer_ref field.
When it does this, it sometimes just points it at an existing ref in
the src list, but sometimes it allocates a new ref and points to that.

So there is no sane way to free the result. As there is no indication that the caller shouldn't be able to free the src and dst lists after it is done, it was IMO a latent bug.

Initially I tried to fix this by modifying free_refs() to make two passes over the list passed to it, once to mark each peer_ref, then a second time to clear only those peer_refs it had not already seen. I did this because when I first saw the double free I was only freeing the dst list. It took me a while to realize the cause was two refs in the dst list having the same peer_ref.

But then I realized my caller needed to clear the src list as well, and saw that the problem was really in match_heads(), not in free'ing the result.

> So I'd queue this as the first patch in the 13-patch series, dropping 10/13?
> What should happen to 11/13?

I sent you a message off-list you may not have read yet. I'm re-rolling the entire js/remote-set-head for you off of the current master to get rid of any dependencies on pu, with jk/head-lookup on the end of the series instead of in the middle. I needed to rebase off master since I have a dependency on cfa1ee6 which is now in master, but wasn't when you spawned js/remote-set-head initially.

j.
Previous: Junio C HamanoNext: Junio C Hamano
Message 26 of 38 in “New output style for git remote show”
  1. 00/13 New output style for git remote showJay Soffian, Feb 23, 2009
  2. 01/13 remote: rename variable and eliminate redundant function callJay Soffian, Feb 23, 2009
  3. 02/13 remote: remove unused code in get_ref_statesJay Soffian, Feb 23, 2009
  4. 03/13 remote: fix two inconsistencies in the output of "show <remote>"Jay Soffian, Feb 23, 2009
  5. 04/13 remote: make get_remote_ref_states() always populate states.trackedJay Soffian, Feb 23, 2009
  6. Junio C HamanoFeb 24, 2009
  7. Jay SoffianFeb 24, 2009
  8. Jay SoffianFeb 24, 2009
  9. 05/13 remote: name remote_refs consistentlyJay Soffian, Feb 23, 2009
  10. 06/13 string-list: new for_each_string_list() functionJay Soffian, Feb 23, 2009
  11. 07/13 remote: new show output styleJay Soffian, Feb 23, 2009
  12. Jeff KingFeb 23, 2009
  13. Marc BranchaudFeb 23, 2009
  14. 08/13 refactor duplicated get_local_heads() to remote.cJay Soffian, Feb 23, 2009
  15. 09/13 refactor duplicated ref_newer() to remote.cJay Soffian, Feb 23, 2009
  16. Jeff KingFeb 23, 2009
  17. 09/13 refactor duplicated ref_newer() to remote.cJay Soffian, Feb 23, 2009
  18. Johannes SixtFeb 23, 2009
  19. Jay SoffianFeb 23, 2009
  20. 10/13 remote.c: make match_refs() copy src ref before assigning to peer_refJay Soffian, Feb 23, 2009
  21. Junio C HamanoFeb 24, 2009
  22. Jay SoffianFeb 24, 2009
  23. Junio C HamanoFeb 24, 2009
  24. remote.c: make match_refs() copy src ref before assigning to peer_refJay Soffian, Feb 24, 2009
  25. Junio C HamanoFeb 24, 2009
  26. Jay SoffianFeb 24, 2009
  27. Junio C HamanoFeb 24, 2009
  28. 11/13 remote.c: don't short-circuit match_refs() when error in match_explicit_refs()Jay Soffian, Feb 23, 2009
  29. Junio C HamanoFeb 24, 2009
  30. Jay SoffianFeb 24, 2009
  31. 12/13 remote.c: refactor get_remote_ref_states()Jay Soffian, Feb 23, 2009
  32. Jeff KingFeb 23, 2009
  33. Jay SoffianFeb 23, 2009
  34. Jay SoffianFeb 23, 2009
  35. Jeff KingFeb 24, 2009
  36. 13/13 remote: new show output style for push refspecsJay Soffian, Feb 23, 2009
  37. Jeff KingFeb 23, 2009
  38. Jay SoffianFeb 23, 2009

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.