Skip to content

Commit f83918e

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b87d8d commit f83918e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/fetch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ static int add_existing(const char *refname, const unsigned char *sha1,
571571
{
572572
struct string_list *list = (struct string_list *)cbdata;
573573
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);
575576
return 0;
576577
}
577578

@@ -636,7 +637,7 @@ static void find_non_local_tags(struct transport *transport,
636637
item = string_list_insert(&remote_refs, ref->name);
637638
item->util = (void *)ref->old_sha1;
638639
}
639-
string_list_clear(&existing_refs, 0);
640+
string_list_clear(&existing_refs, 1);
640641

641642
/*
642643
* We may have a final lightweight tag that needs to be
@@ -782,7 +783,7 @@ static int do_fetch(struct transport *transport,
782783
}
783784

784785
cleanup:
785-
string_list_clear(&existing_refs, 0);
786+
string_list_clear(&existing_refs, 1);
786787
return retcode;
787788
}
788789

0 commit comments

Comments
 (0)