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

[PATCH] remote: Fix glibc error in ref_remove_duplicates

From
Julian Phillips <julian@quantumfyre.co.uk>
Date
Nov 13, 2009, 21:25 UTC
Message-ID
<20091113212557.40912.20173.julian@quantumfyre.co.uk>
In-Reply-To
<alpine.LFD.2.00.0911131152120.16711@xanadu.home>

In ref_remove_duplicates, when we encounter a duplicate and remove it from the list we need to make sure that the prev pointer stays pointing at the last entry and also skip over adding the just freed entry to the string_list.

Previously fetch could crash with: *** glibc detected *** git: corrupted double-linked list: ...

Also add a test to try and catch problems with duplicate removal in the future.

Acked-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
---

Thanks to Rene for pointing me at the problem before I even looked at it. Made it much easier to figure out what was going wrong. :)

 remote.c         |    2 ++
 t/t5510-fetch.sh |   11 +++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/remote.c b/remote.c
index 4f9f0cc..002f790 100644
--- a/remote.c
+++ b/remote.c
@@ -754,6 +754,8 @@ void ref_remove_duplicates(struct ref *ref_map)
 			prev->next = ref_map->next;
 			free(ref_map->peer_ref);
 			free(ref_map);
+			ref_map = prev; // don't change the prev pointer.
+			continue;
 		}
 
 		item = string_list_insert(ref_map->peer_ref->name, &refs);
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index d13c806..169af1e 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -341,4 +341,15 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
 
 '
 
+test_expect_success "should be able to fetch with duplicate refspecs" '
+        mkdir dups &&
+        cd dups &&
+        git init &&
+        git config branch.master.remote three &&
+        git config remote.three.url ../three/.git &&
+        git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
+        git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
+        git fetch three
+'
+
 test_done
-- 
1.6.5.rc2
Previous: Eric Raible
Message 8 of 8 in “Git in next is broken”
  1. Nicolas PitreNov 12, 2009
  2. René ScharfeNov 12, 2009
  3. Julian PhillipsNov 12, 2009
  4. Nicolas PitreNov 13, 2009
  5. Julian PhillipsNov 13, 2009
  6. Nicolas PitreNov 13, 2009
  7. Eric RaibleNov 13, 2009
  8. remote: Fix glibc error in ref_remove_duplicatesJulian Phillips, Nov 13, 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.