From b87dbcc89940edbf92cbab381001542a7cac3627 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sat, 25 May 2013 11:08:01 +0200 Subject: fetch: make own copies of refnames Do not retain references to refnames passed to the each_ref_fn callback add_existing(), because their lifetime is not guaranteed. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/fetch.c') diff --git a/builtin/fetch.c b/builtin/fetch.c index 4b6b1dfe66..f9491154ee 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -590,7 +590,7 @@ static void find_non_local_tags(struct transport *transport, struct ref **head, struct ref ***tail) { - struct string_list existing_refs = STRING_LIST_INIT_NODUP; + struct string_list existing_refs = STRING_LIST_INIT_DUP; struct string_list remote_refs = STRING_LIST_INIT_NODUP; const struct ref *ref; struct string_list_item *item = NULL; @@ -693,7 +693,7 @@ static int truncate_fetch_head(void) static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { - struct string_list existing_refs = STRING_LIST_INIT_NODUP; + struct string_list existing_refs = STRING_LIST_INIT_DUP; struct string_list_item *peer_item = NULL; struct ref *ref_map; struct ref *rm; -- cgit 1.2.3-korg From 6f64a16faff0189d54cf30854483493574476c6e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sat, 25 May 2013 11:08:15 +0200 Subject: do_fetch(): reduce scope of peer_item Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin/fetch.c') diff --git a/builtin/fetch.c b/builtin/fetch.c index f9491154ee..80c6e37d27 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -694,7 +694,6 @@ static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { struct string_list existing_refs = STRING_LIST_INIT_DUP; - struct string_list_item *peer_item = NULL; struct ref *ref_map; struct ref *rm; int autotags = (transport->remote->fetch_tags == 1); @@ -724,8 +723,9 @@ static int do_fetch(struct transport *transport, for (rm = ref_map; rm; rm = rm->next) { if (rm->peer_ref) { - peer_item = string_list_lookup(&existing_refs, - rm->peer_ref->name); + struct string_list_item *peer_item = + string_list_lookup(&existing_refs, + rm->peer_ref->name); if (peer_item) hashcpy(rm->peer_ref->old_sha1, peer_item->util); -- cgit 1.2.3-korg From 5b87d8d3f53c1dfb54027123af612488abc85006 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sat, 25 May 2013 11:08:16 +0200 Subject: do_fetch(): clean up existing_refs before exiting Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'builtin/fetch.c') diff --git a/builtin/fetch.c b/builtin/fetch.c index 80c6e37d27..48df5fa480 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -697,6 +697,7 @@ static int do_fetch(struct transport *transport, struct ref *ref_map; struct ref *rm; int autotags = (transport->remote->fetch_tags == 1); + int retcode = 0; for_each_ref(add_existing, &existing_refs); @@ -712,9 +713,9 @@ static int do_fetch(struct transport *transport, /* if not appending, truncate FETCH_HEAD */ if (!append && !dry_run) { - int errcode = truncate_fetch_head(); - if (errcode) - return errcode; + retcode = truncate_fetch_head(); + if (retcode) + goto cleanup; } ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags); @@ -736,7 +737,8 @@ static int do_fetch(struct transport *transport, transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1"); if (fetch_refs(transport, ref_map)) { free_refs(ref_map); - return 1; + retcode = 1; + goto cleanup; } if (prune) { /* If --tags was specified, pretend the user gave us the canonical tags refspec */ @@ -779,7 +781,9 @@ static int do_fetch(struct transport *transport, free_refs(ref_map); } - return 0; + cleanup: + string_list_clear(&existing_refs, 0); + return retcode; } static void set_option(const char *name, const char *value) -- cgit 1.2.3-korg From f83918edcb6fbcd1c5d8378c11e57edcc47bd232 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sat, 25 May 2013 11:08:17 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/fetch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'builtin/fetch.c') diff --git a/builtin/fetch.c b/builtin/fetch.c index 48df5fa480..fa6fe44147 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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; } @@ -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 @@ -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; } -- cgit 1.2.3-korg