@@ -119,15 +119,24 @@ static int add_ref(transport_local *t, const char *name)
119
119
120
120
static int store_refs (transport_local * t )
121
121
{
122
- unsigned int i ;
122
+ size_t i ;
123
+ git_remote_head * head ;
123
124
git_strarray ref_names = {0 };
124
125
125
126
assert (t );
126
127
127
- if (git_reference_list (& ref_names , t -> repo ) < 0 ||
128
- git_vector_init (& t -> refs , ref_names .count , NULL ) < 0 )
128
+ if (git_reference_list (& ref_names , t -> repo ) < 0 )
129
129
goto on_error ;
130
130
131
+ /* Clear all heads we might have fetched in a previous connect */
132
+ git_vector_foreach (& t -> refs , i , head ) {
133
+ git__free (head -> name );
134
+ git__free (head );
135
+ }
136
+
137
+ /* Clear the vector so we can reuse it */
138
+ git_vector_clear (& t -> refs );
139
+
131
140
/* Sort the references first */
132
141
git__tsort ((void * * )ref_names .strings , ref_names .count , & git__strcmp_cb );
133
142
@@ -571,8 +580,6 @@ static void local_cancel(git_transport *transport)
571
580
static int local_close (git_transport * transport )
572
581
{
573
582
transport_local * t = (transport_local * )transport ;
574
- size_t i ;
575
- git_remote_head * head ;
576
583
577
584
t -> connected = 0 ;
578
585
@@ -586,19 +593,21 @@ static int local_close(git_transport *transport)
586
593
t -> url = NULL ;
587
594
}
588
595
589
- git_vector_foreach (& t -> refs , i , head ) {
590
- git__free (head -> name );
591
- git__free (head );
592
- }
593
-
594
- git_vector_free (& t -> refs );
595
-
596
596
return 0 ;
597
597
}
598
598
599
599
static void local_free (git_transport * transport )
600
600
{
601
601
transport_local * t = (transport_local * )transport ;
602
+ size_t i ;
603
+ git_remote_head * head ;
604
+
605
+ git_vector_foreach (& t -> refs , i , head ) {
606
+ git__free (head -> name );
607
+ git__free (head );
608
+ }
609
+
610
+ git_vector_free (& t -> refs );
602
611
603
612
/* Close the transport, if it's still open. */
604
613
local_close (transport );
@@ -632,6 +641,7 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param)
632
641
t -> parent .read_flags = local_read_flags ;
633
642
t -> parent .cancel = local_cancel ;
634
643
644
+ git_vector_init (& t -> refs , 0 , NULL );
635
645
t -> owner = owner ;
636
646
637
647
* out = (git_transport * ) t ;
0 commit comments