add_existing(): do not retain a reference to sha1
Its lifetime is not guaranteed, so make a copy. Free the memory when the string_list is cleared. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
May 25, 2013 at 11:08 UTC
f83918edcb6fbcd1c5d8378c11e57edcc47bd232
1 file changed
+4
-3
builtin/fetch.c
+4
-3
@@ -571,7 +571,8 @@ static int add_existing(const char *refname, const unsigned char *sha1,
571
{
572
struct string_list *list = (struct string_list *)cbdata;
573
struct string_list_item *item = string_list_insert(list, refname);
574
- item->util = (void *)sha1;
574
+ item->util = xmalloc(20);
575
+ hashcpy(item->util, sha1);
576
return 0;
577
}
578
@@ -636,7 +637,7 @@ static void find_non_local_tags(struct transport *transport,
637
item = string_list_insert(&remote_refs, ref->name);
638
item->util = (void *)ref->old_sha1;
639
}
639
- string_list_clear(&existing_refs, 0);
640
+ string_list_clear(&existing_refs, 1);
641
642
/*
643
* We may have a final lightweight tag that needs to be
@@ -782,7 +783,7 @@ static int do_fetch(struct transport *transport,
783
}
784
785
cleanup:
785
- string_list_clear(&existing_refs, 0);
786
+ string_list_clear(&existing_refs, 1);
787
return retcode;
788
}
789