@@ -69,6 +69,15 @@ static inline void llist_init(struct llist **list)
69
69
(* list )-> size = 0 ;
70
70
}
71
71
72
+ static void llist_free (struct llist * list )
73
+ {
74
+ for (struct llist_item * i = list -> front , * next ; i ; i = next ) {
75
+ next = i -> next ;
76
+ llist_item_put (i );
77
+ }
78
+ free (list );
79
+ }
80
+
72
81
static struct llist * llist_copy (struct llist * list )
73
82
{
74
83
struct llist * ret ;
@@ -206,6 +215,14 @@ static inline struct pack_list * pack_list_insert(struct pack_list **pl,
206
215
return p ;
207
216
}
208
217
218
+ static void pack_list_free (struct pack_list * pl )
219
+ {
220
+ for (struct pack_list * next ; pl ; pl = next ) {
221
+ next = pl -> next ;
222
+ free (pl );
223
+ }
224
+ }
225
+
209
226
static inline size_t pack_list_size (struct pack_list * pl )
210
227
{
211
228
size_t ret = 0 ;
@@ -419,7 +436,8 @@ static void minimize(struct pack_list **min)
419
436
420
437
/* return if there are no objects missing from the unique set */
421
438
if (missing -> size == 0 ) {
422
- free (missing );
439
+ llist_free (missing );
440
+ pack_list_free (non_unique );
423
441
return ;
424
442
}
425
443
@@ -434,6 +452,8 @@ static void minimize(struct pack_list **min)
434
452
}
435
453
436
454
while (non_unique ) {
455
+ struct pack_list * next ;
456
+
437
457
/* sort the non_unique packs, greater size of remaining_objects first */
438
458
sort_pack_list (& non_unique );
439
459
if (non_unique -> remaining_objects -> size == 0 )
@@ -444,8 +464,14 @@ static void minimize(struct pack_list **min)
444
464
for (pl = non_unique -> next ; pl && pl -> remaining_objects -> size > 0 ; pl = pl -> next )
445
465
llist_sorted_difference_inplace (pl -> remaining_objects , non_unique -> remaining_objects );
446
466
447
- non_unique = non_unique -> next ;
467
+ next = non_unique -> next ;
468
+ free (non_unique );
469
+ non_unique = next ;
448
470
}
471
+
472
+ pack_list_free (non_unique );
473
+ llist_free (unique_pack_objects );
474
+ llist_free (missing );
449
475
}
450
476
451
477
static void load_all_objects (void )
@@ -565,7 +591,6 @@ static void load_all(void)
565
591
int cmd_pack_redundant (int argc , const char * * argv , const char * prefix UNUSED , struct repository * repo UNUSED ) {
566
592
int i ; int i_still_use_this = 0 ; struct pack_list * min = NULL , * red , * pl ;
567
593
struct llist * ignore ;
568
- struct object_id * oid ;
569
594
char buf [GIT_MAX_HEXSZ + 2 ]; /* hex hash + \n + \0 */
570
595
571
596
if (argc == 2 && !strcmp (argv [1 ], "-h" ))
@@ -625,11 +650,11 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
625
650
/* ignore objects given on stdin */
626
651
llist_init (& ignore );
627
652
if (!isatty (0 )) {
653
+ struct object_id oid ;
628
654
while (fgets (buf , sizeof (buf ), stdin )) {
629
- oid = xmalloc (sizeof (* oid ));
630
- if (get_oid_hex (buf , oid ))
655
+ if (get_oid_hex (buf , & oid ))
631
656
die ("Bad object ID on stdin: %s" , buf );
632
- llist_insert_sorted_unique (ignore , oid , NULL );
657
+ llist_insert_sorted_unique (ignore , & oid , NULL );
633
658
}
634
659
}
635
660
llist_sorted_difference_inplace (all_objects , ignore );
@@ -671,5 +696,8 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
671
696
fprintf (stderr , "%luMB of redundant packs in total.\n" ,
672
697
(unsigned long )pack_set_bytecount (red )/(1024 * 1024 ));
673
698
699
+ pack_list_free (red );
700
+ pack_list_free (min );
701
+ llist_free (ignore );
674
702
return 0 ;
675
703
}
0 commit comments