@@ -46,7 +46,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
46
46
int cmd_fetch_pack (int argc , const char * * argv , const char * prefix UNUSED )
47
47
{
48
48
int i , ret ;
49
- struct ref * ref = NULL ;
49
+ struct ref * fetched_refs = NULL , * remote_refs = NULL ;
50
50
const char * dest = NULL ;
51
51
struct ref * * sought = NULL ;
52
52
int nr_sought = 0 , alloc_sought = 0 ;
@@ -228,19 +228,20 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
228
228
version = discover_version (& reader );
229
229
switch (version ) {
230
230
case protocol_v2 :
231
- get_remote_refs (fd [1 ], & reader , & ref , 0 , NULL , NULL ,
231
+ get_remote_refs (fd [1 ], & reader , & remote_refs , 0 , NULL , NULL ,
232
232
args .stateless_rpc );
233
233
break ;
234
234
case protocol_v1 :
235
235
case protocol_v0 :
236
- get_remote_heads (& reader , & ref , 0 , NULL , & shallow );
236
+ get_remote_heads (& reader , & remote_refs , 0 , NULL , & shallow );
237
237
break ;
238
238
case protocol_unknown_version :
239
239
BUG ("unknown protocol version" );
240
240
}
241
241
242
- ref = fetch_pack (& args , fd , ref , sought , nr_sought ,
242
+ fetched_refs = fetch_pack (& args , fd , remote_refs , sought , nr_sought ,
243
243
& shallow , pack_lockfiles_ptr , version );
244
+
244
245
if (pack_lockfiles .nr ) {
245
246
int i ;
246
247
@@ -260,7 +261,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
260
261
if (finish_connect (conn ))
261
262
return 1 ;
262
263
263
- ret = !ref ;
264
+ ret = !fetched_refs ;
264
265
265
266
/*
266
267
* If the heads to pull were given, we should have consumed
@@ -270,11 +271,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
270
271
*/
271
272
ret |= report_unmatched_refs (sought , nr_sought );
272
273
273
- while ( ref ) {
274
+ for ( struct ref * ref = fetched_refs ; ref ; ref = ref -> next )
274
275
printf ("%s %s\n" ,
275
276
oid_to_hex (& ref -> old_oid ), ref -> name );
276
- ref = ref -> next ;
277
- }
278
277
278
+ for (size_t i = 0 ; i < nr_sought ; i ++ )
279
+ free_one_ref (sought [i ]);
280
+ free (sought );
281
+ free_refs (fetched_refs );
282
+ free_refs (remote_refs );
279
283
return ret ;
280
284
}
0 commit comments