@@ -46,7 +46,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
4646int cmd_fetch_pack (int argc , const char * * argv , const char * prefix UNUSED )
4747{
4848 int i , ret ;
49- struct ref * ref = NULL ;
49+ struct ref * fetched_refs = NULL , * remote_refs = NULL ;
5050 const char * dest = NULL ;
5151 struct ref * * sought = NULL ;
5252 int nr_sought = 0 , alloc_sought = 0 ;
@@ -228,19 +228,20 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
228228 version = discover_version (& reader );
229229 switch (version ) {
230230 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 ,
232232 args .stateless_rpc );
233233 break ;
234234 case protocol_v1 :
235235 case protocol_v0 :
236- get_remote_heads (& reader , & ref , 0 , NULL , & shallow );
236+ get_remote_heads (& reader , & remote_refs , 0 , NULL , & shallow );
237237 break ;
238238 case protocol_unknown_version :
239239 BUG ("unknown protocol version" );
240240 }
241241
242- ref = fetch_pack (& args , fd , ref , sought , nr_sought ,
242+ fetched_refs = fetch_pack (& args , fd , remote_refs , sought , nr_sought ,
243243 & shallow , pack_lockfiles_ptr , version );
244+
244245 if (pack_lockfiles .nr ) {
245246 int i ;
246247
@@ -260,7 +261,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
260261 if (finish_connect (conn ))
261262 return 1 ;
262263
263- ret = !ref ;
264+ ret = !fetched_refs ;
264265
265266 /*
266267 * 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)
270271 */
271272 ret |= report_unmatched_refs (sought , nr_sought );
272273
273- while ( ref ) {
274+ for ( struct ref * ref = fetched_refs ; ref ; ref = ref -> next )
274275 printf ("%s %s\n" ,
275276 oid_to_hex (& ref -> old_oid ), ref -> name );
276- ref = ref -> next ;
277- }
278277
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 );
279283 return ret ;
280284}
0 commit comments