@@ -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)
@@ -440,11 +440,19 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
440440 free_commit_list (list -> next );
441441 best = list ;
442442 best -> next = NULL ;
443+ } else {
444+ for (p = list ; p != best ; p = next ) {
445+ next = p -> next ;
446+ free (p );
447+ }
443448 }
444449 * reaches = weight (best );
450+ } else {
451+ free_commit_list (* commit_list );
445452 }
446- free (weights );
447453 * commit_list = best ;
454+
455+ free (weights );
448456 clear_commit_weight (& commit_weight );
449457}
450458
@@ -456,6 +464,7 @@ static int register_ref(const char *refname, const char *referent UNUSED, const
456464 strbuf_addstr (& good_prefix , "-" );
457465
458466 if (!strcmp (refname , term_bad )) {
467+ free (current_bad_oid );
459468 current_bad_oid = xmalloc (sizeof (* current_bad_oid ));
460469 oidcpy (current_bad_oid , oid );
461470 } else if (starts_with (refname , good_prefix .buf )) {
@@ -556,8 +565,11 @@ struct commit_list *filter_skipped(struct commit_list *list,
556565 tried = & list -> next ;
557566 } else {
558567 if (!show_all ) {
559- if (!skipped_first || !* skipped_first )
568+ if (!skipped_first || !* skipped_first ) {
569+ free_commit_list (next );
570+ free_commit_list (filtered );
560571 return list ;
572+ }
561573 } else if (skipped_first && !* skipped_first ) {
562574 /* This means we know it's not skipped */
563575 * skipped_first = -1 ;
@@ -613,7 +625,7 @@ static int sqrti(int val)
613625
614626static struct commit_list * skip_away (struct commit_list * list , int count )
615627{
616- struct commit_list * cur , * previous ;
628+ struct commit_list * cur , * previous , * result = list ;
617629 int prn , index , i ;
618630
619631 prn = get_prn (count );
@@ -625,15 +637,23 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
625637 for (i = 0 ; cur ; cur = cur -> next , i ++ ) {
626638 if (i == index ) {
627639 if (!oideq (& cur -> item -> object .oid , current_bad_oid ))
628- return cur ;
629- if (previous )
630- return previous ;
631- return list ;
640+ result = cur ;
641+ else if (previous )
642+ result = previous ;
643+ else
644+ result = list ;
645+ break ;
632646 }
633647 previous = cur ;
634648 }
635649
636- return list ;
650+ for (cur = list ; cur != result ; ) {
651+ struct commit_list * next = cur -> next ;
652+ free (cur );
653+ cur = next ;
654+ }
655+
656+ return result ;
637657}
638658
639659static struct commit_list * managed_skipped (struct commit_list * list ,
@@ -801,6 +821,8 @@ static enum bisect_error handle_bad_merge_base(void)
801821 "between %s and [%s].\n" ),
802822 bad_hex , term_bad , term_good , bad_hex , good_hex );
803823 }
824+
825+ free (good_hex );
804826 return BISECT_MERGE_BASE_CHECK ;
805827 }
806828
@@ -848,8 +870,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
848870 rev + 1 , & result ) < 0 )
849871 exit (128 );
850872
851- for (; result ; result = result -> next ) {
852- const struct object_id * mb = & result -> item -> object .oid ;
873+ for (struct commit_list * l = result ; l ; l = l -> next ) {
874+ const struct object_id * mb = & l -> item -> object .oid ;
853875 if (oideq (mb , current_bad_oid )) {
854876 res = handle_bad_merge_base ();
855877 break ;
@@ -985,24 +1007,28 @@ static void show_commit(struct commit *commit)
9851007 * We read them and store them to adapt the messages accordingly.
9861008 * Default is bad/good.
9871009 */
988- void read_bisect_terms (const char * * read_bad , const char * * read_good )
1010+ void read_bisect_terms (char * * read_bad , char * * read_good )
9891011{
9901012 struct strbuf str = STRBUF_INIT ;
9911013 const char * filename = git_path_bisect_terms ();
9921014 FILE * fp = fopen (filename , "r" );
9931015
9941016 if (!fp ) {
9951017 if (errno == ENOENT ) {
996- * read_bad = "bad" ;
997- * read_good = "good" ;
1018+ free (* read_bad );
1019+ * read_bad = xstrdup ("bad" );
1020+ free (* read_good );
1021+ * read_good = xstrdup ("good" );
9981022 return ;
9991023 } else {
10001024 die_errno (_ ("could not read file '%s'" ), filename );
10011025 }
10021026 } else {
10031027 strbuf_getline_lf (& str , fp );
1028+ free (* read_bad );
10041029 * read_bad = strbuf_detach (& str , NULL );
10051030 strbuf_getline_lf (& str , fp );
1031+ free (* read_good );
10061032 * read_good = strbuf_detach (& str , NULL );
10071033 }
10081034 strbuf_release (& str );
@@ -1024,7 +1050,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10241050{
10251051 struct strvec rev_argv = STRVEC_INIT ;
10261052 struct rev_info revs = REV_INFO_INIT ;
1027- struct commit_list * tried ;
1053+ struct commit_list * tried = NULL ;
10281054 int reaches = 0 , all = 0 , nr , steps ;
10291055 enum bisect_error res = BISECT_OK ;
10301056 struct object_id * bisect_rev ;
@@ -1091,7 +1117,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10911117 if (oideq (bisect_rev , current_bad_oid )) {
10921118 res = error_if_skipped_commits (tried , current_bad_oid );
10931119 if (res )
1094- return res ;
1120+ goto cleanup ;
10951121 printf ("%s is the first %s commit\n" , oid_to_hex (bisect_rev ),
10961122 term_bad );
10971123
@@ -1125,6 +1151,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
11251151
11261152 res = bisect_checkout (bisect_rev , no_checkout );
11271153cleanup :
1154+ free_commit_list (tried );
11281155 release_revisions (& revs );
11291156 strvec_clear (& rev_argv );
11301157 return res ;
0 commit comments