Skip to content

Commit

Permalink
add_existing(): do not retain a reference to sha1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jun 2, 2013
1 parent 5b87d8d commit f83918e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ static int add_existing(const char *refname, const unsigned char *sha1,
{
struct string_list *list = (struct string_list *)cbdata;
struct string_list_item *item = string_list_insert(list, refname);
item->util = (void *)sha1;
item->util = xmalloc(20);
hashcpy(item->util, sha1);
return 0;
}

Expand Down Expand Up @@ -636,7 +637,7 @@ static void find_non_local_tags(struct transport *transport,
item = string_list_insert(&remote_refs, ref->name);
item->util = (void *)ref->old_sha1;
}
string_list_clear(&existing_refs, 0);
string_list_clear(&existing_refs, 1);

/*
* We may have a final lightweight tag that needs to be
Expand Down Expand Up @@ -782,7 +783,7 @@ static int do_fetch(struct transport *transport,
}

cleanup:
string_list_clear(&existing_refs, 0);
string_list_clear(&existing_refs, 1);
return retcode;
}

Expand Down

0 comments on commit f83918e

Please sign in to comment.