@@ -243,6 +243,17 @@ static struct branch *make_branch(struct remote_state *remote_state,
243
243
return ret ;
244
244
}
245
245
246
+ static void branch_release (struct branch * branch )
247
+ {
248
+ free ((char * )branch -> name );
249
+ free ((char * )branch -> refname );
250
+ free (branch -> remote_name );
251
+ free (branch -> pushremote_name );
252
+ for (int i = 0 ; i < branch -> merge_nr ; i ++ )
253
+ refspec_item_clear (branch -> merge [i ]);
254
+ free (branch -> merge );
255
+ }
256
+
246
257
static struct rewrite * make_rewrite (struct rewrites * r ,
247
258
const char * base , size_t len )
248
259
{
@@ -263,6 +274,14 @@ static struct rewrite *make_rewrite(struct rewrites *r,
263
274
return ret ;
264
275
}
265
276
277
+ static void rewrites_release (struct rewrites * r )
278
+ {
279
+ for (int i = 0 ; i < r -> rewrite_nr ; i ++ )
280
+ free ((char * )r -> rewrite [i ]-> base );
281
+ free (r -> rewrite );
282
+ memset (r , 0 , sizeof (* r ));
283
+ }
284
+
266
285
static void add_instead_of (struct rewrite * rewrite , const char * instead_of )
267
286
{
268
287
ALLOC_GROW (rewrite -> instead_of , rewrite -> instead_of_nr + 1 , rewrite -> instead_of_alloc );
@@ -373,8 +392,10 @@ static int handle_config(const char *key, const char *value,
373
392
return -1 ;
374
393
branch = make_branch (remote_state , name , namelen );
375
394
if (!strcmp (subkey , "remote" )) {
395
+ FREE_AND_NULL (branch -> remote_name );
376
396
return git_config_string (& branch -> remote_name , key , value );
377
397
} else if (!strcmp (subkey , "pushremote" )) {
398
+ FREE_AND_NULL (branch -> pushremote_name );
378
399
return git_config_string (& branch -> pushremote_name , key , value );
379
400
} else if (!strcmp (subkey , "merge" )) {
380
401
if (!value )
@@ -406,9 +427,11 @@ static int handle_config(const char *key, const char *value,
406
427
return 0 ;
407
428
408
429
/* Handle remote.* variables */
409
- if (!name && !strcmp (subkey , "pushdefault" ))
430
+ if (!name && !strcmp (subkey , "pushdefault" )) {
431
+ FREE_AND_NULL (remote_state -> pushremote_name );
410
432
return git_config_string (& remote_state -> pushremote_name , key ,
411
433
value );
434
+ }
412
435
413
436
if (!name )
414
437
return 0 ;
@@ -475,12 +498,15 @@ static int handle_config(const char *key, const char *value,
475
498
else if (!strcmp (value , "--tags" ))
476
499
remote -> fetch_tags = 2 ;
477
500
} else if (!strcmp (subkey , "proxy" )) {
501
+ FREE_AND_NULL (remote -> http_proxy );
478
502
return git_config_string (& remote -> http_proxy ,
479
503
key , value );
480
504
} else if (!strcmp (subkey , "proxyauthmethod" )) {
505
+ FREE_AND_NULL (remote -> http_proxy_authmethod );
481
506
return git_config_string (& remote -> http_proxy_authmethod ,
482
507
key , value );
483
508
} else if (!strcmp (subkey , "vcs" )) {
509
+ FREE_AND_NULL (remote -> foreign_vcs );
484
510
return git_config_string (& remote -> foreign_vcs , key , value );
485
511
}
486
512
return 0 ;
@@ -2797,16 +2823,26 @@ struct remote_state *remote_state_new(void)
2797
2823
2798
2824
void remote_state_clear (struct remote_state * remote_state )
2799
2825
{
2826
+ struct hashmap_iter iter ;
2827
+ struct branch * b ;
2800
2828
int i ;
2801
2829
2802
2830
for (i = 0 ; i < remote_state -> remotes_nr ; i ++ )
2803
2831
remote_clear (remote_state -> remotes [i ]);
2804
2832
FREE_AND_NULL (remote_state -> remotes );
2833
+ FREE_AND_NULL (remote_state -> pushremote_name );
2805
2834
remote_state -> remotes_alloc = 0 ;
2806
2835
remote_state -> remotes_nr = 0 ;
2807
2836
2837
+ rewrites_release (& remote_state -> rewrites );
2838
+ rewrites_release (& remote_state -> rewrites_push );
2839
+
2808
2840
hashmap_clear_and_free (& remote_state -> remotes_hash , struct remote , ent );
2809
- hashmap_clear_and_free (& remote_state -> branches_hash , struct remote , ent );
2841
+ hashmap_for_each_entry (& remote_state -> branches_hash , & iter , b , ent ) {
2842
+ branch_release (b );
2843
+ free (b );
2844
+ }
2845
+ hashmap_clear (& remote_state -> branches_hash );
2810
2846
}
2811
2847
2812
2848
/*
0 commit comments