Skip to content

Commit 5b87d8d

Browse files
mhaggergitster
authored andcommitted
do_fetch(): clean up existing_refs before exiting
Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f64a16 commit 5b87d8d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

builtin/fetch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ static int do_fetch(struct transport *transport,
697697
struct ref *ref_map;
698698
struct ref *rm;
699699
int autotags = (transport->remote->fetch_tags == 1);
700+
int retcode = 0;
700701

701702
for_each_ref(add_existing, &existing_refs);
702703

@@ -712,9 +713,9 @@ static int do_fetch(struct transport *transport,
712713

713714
/* if not appending, truncate FETCH_HEAD */
714715
if (!append && !dry_run) {
715-
int errcode = truncate_fetch_head();
716-
if (errcode)
717-
return errcode;
716+
retcode = truncate_fetch_head();
717+
if (retcode)
718+
goto cleanup;
718719
}
719720

720721
ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
@@ -736,7 +737,8 @@ static int do_fetch(struct transport *transport,
736737
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
737738
if (fetch_refs(transport, ref_map)) {
738739
free_refs(ref_map);
739-
return 1;
740+
retcode = 1;
741+
goto cleanup;
740742
}
741743
if (prune) {
742744
/* If --tags was specified, pretend the user gave us the canonical tags refspec */
@@ -779,7 +781,9 @@ static int do_fetch(struct transport *transport,
779781
free_refs(ref_map);
780782
}
781783

782-
return 0;
784+
cleanup:
785+
string_list_clear(&existing_refs, 0);
786+
return retcode;
783787
}
784788

785789
static void set_option(const char *name, const char *value)

0 commit comments

Comments
 (0)