@@ -28,8 +28,8 @@ static struct oid_array skipped_revs;
2828
2929static struct object_id * current_bad_oid ;
3030
31- static const char * term_bad ;
32- static const char * term_good ;
31+ static char * term_bad ;
32+ static char * term_good ;
3333
3434/* Remember to update object flag allocation in object.h */
3535#define COUNTED (1u<<16)
@@ -442,9 +442,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
442442 best -> next = NULL ;
443443 }
444444 * reaches = weight (best );
445+ } else {
446+ free_commit_list (* commit_list );
445447 }
446- free (weights );
447448 * commit_list = best ;
449+
450+ free (weights );
448451 clear_commit_weight (& commit_weight );
449452}
450453
@@ -456,6 +459,7 @@ static int register_ref(const char *refname, const char *referent UNUSED, const
456459 strbuf_addstr (& good_prefix , "-" );
457460
458461 if (!strcmp (refname , term_bad )) {
462+ free (current_bad_oid );
459463 current_bad_oid = xmalloc (sizeof (* current_bad_oid ));
460464 oidcpy (current_bad_oid , oid );
461465 } else if (starts_with (refname , good_prefix .buf )) {
@@ -556,8 +560,11 @@ struct commit_list *filter_skipped(struct commit_list *list,
556560 tried = & list -> next ;
557561 } else {
558562 if (!show_all ) {
559- if (!skipped_first || !* skipped_first )
563+ if (!skipped_first || !* skipped_first ) {
564+ free_commit_list (next );
565+ free_commit_list (filtered );
560566 return list ;
567+ }
561568 } else if (skipped_first && !* skipped_first ) {
562569 /* This means we know it's not skipped */
563570 * skipped_first = -1 ;
@@ -613,7 +620,7 @@ static int sqrti(int val)
613620
614621static struct commit_list * skip_away (struct commit_list * list , int count )
615622{
616- struct commit_list * cur , * previous ;
623+ struct commit_list * cur , * previous , * result = list ;
617624 int prn , index , i ;
618625
619626 prn = get_prn (count );
@@ -625,15 +632,23 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
625632 for (i = 0 ; cur ; cur = cur -> next , i ++ ) {
626633 if (i == index ) {
627634 if (!oideq (& cur -> item -> object .oid , current_bad_oid ))
628- return cur ;
629- if (previous )
630- return previous ;
631- return list ;
635+ result = cur ;
636+ else if (previous )
637+ result = previous ;
638+ else
639+ result = list ;
640+ break ;
632641 }
633642 previous = cur ;
634643 }
635644
636- return list ;
645+ for (cur = list ; cur != result ; ) {
646+ struct commit_list * next = cur -> next ;
647+ free (cur );
648+ cur = next ;
649+ }
650+
651+ return result ;
637652}
638653
639654static struct commit_list * managed_skipped (struct commit_list * list ,
@@ -801,6 +816,8 @@ static enum bisect_error handle_bad_merge_base(void)
801816 "between %s and [%s].\n" ),
802817 bad_hex , term_bad , term_good , bad_hex , good_hex );
803818 }
819+
820+ free (good_hex );
804821 return BISECT_MERGE_BASE_CHECK ;
805822 }
806823
@@ -848,8 +865,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
848865 rev + 1 , & result ) < 0 )
849866 exit (128 );
850867
851- for (; result ; result = result -> next ) {
852- const struct object_id * mb = & result -> item -> object .oid ;
868+ for (struct commit_list * l = result ; l ; l = l -> next ) {
869+ const struct object_id * mb = & l -> item -> object .oid ;
853870 if (oideq (mb , current_bad_oid )) {
854871 res = handle_bad_merge_base ();
855872 break ;
@@ -985,24 +1002,28 @@ static void show_commit(struct commit *commit)
9851002 * We read them and store them to adapt the messages accordingly.
9861003 * Default is bad/good.
9871004 */
988- void read_bisect_terms (const char * * read_bad , const char * * read_good )
1005+ void read_bisect_terms (char * * read_bad , char * * read_good )
9891006{
9901007 struct strbuf str = STRBUF_INIT ;
9911008 const char * filename = git_path_bisect_terms ();
9921009 FILE * fp = fopen (filename , "r" );
9931010
9941011 if (!fp ) {
9951012 if (errno == ENOENT ) {
996- * read_bad = "bad" ;
997- * read_good = "good" ;
1013+ free (* read_bad );
1014+ * read_bad = xstrdup ("bad" );
1015+ free (* read_good );
1016+ * read_good = xstrdup ("good" );
9981017 return ;
9991018 } else {
10001019 die_errno (_ ("could not read file '%s'" ), filename );
10011020 }
10021021 } else {
10031022 strbuf_getline_lf (& str , fp );
1023+ free (* read_bad );
10041024 * read_bad = strbuf_detach (& str , NULL );
10051025 strbuf_getline_lf (& str , fp );
1026+ free (* read_good );
10061027 * read_good = strbuf_detach (& str , NULL );
10071028 }
10081029 strbuf_release (& str );
@@ -1024,7 +1045,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10241045{
10251046 struct strvec rev_argv = STRVEC_INIT ;
10261047 struct rev_info revs = REV_INFO_INIT ;
1027- struct commit_list * tried ;
1048+ struct commit_list * tried = NULL ;
10281049 int reaches = 0 , all = 0 , nr , steps ;
10291050 enum bisect_error res = BISECT_OK ;
10301051 struct object_id * bisect_rev ;
@@ -1091,7 +1112,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10911112 if (oideq (bisect_rev , current_bad_oid )) {
10921113 res = error_if_skipped_commits (tried , current_bad_oid );
10931114 if (res )
1094- return res ;
1115+ goto cleanup ;
10951116 printf ("%s is the first %s commit\n" , oid_to_hex (bisect_rev ),
10961117 term_bad );
10971118
@@ -1125,6 +1146,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
11251146
11261147 res = bisect_checkout (bisect_rev , no_checkout );
11271148cleanup :
1149+ free_commit_list (tried );
11281150 release_revisions (& revs );
11291151 strvec_clear (& rev_argv );
11301152 return res ;
0 commit comments