bisect: fix multiple leaks in `bisect_next_all()`

There are multiple leaks in `bisect_next_all()`. For one we don't free the `tried` commit list. Second, one of the branches uses a direct return instead of jumping to the cleanup code. Fix these by freeing the commit list and converting the return to a goto. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 20, 2024 at 14:39 UTC cfb8a0da55fec9619e4e5b1e9b211ef85e3c9cb3
1 file changed +3 -2
bisect.c
+3 -2
@@ -1031,7 +1031,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1031 {
1032 struct strvec rev_argv = STRVEC_INIT;
1033 struct rev_info revs = REV_INFO_INIT;
1034 - struct commit_list *tried;
1034 + struct commit_list *tried = NULL;
1035 int reaches = 0, all = 0, nr, steps;
1036 enum bisect_error res = BISECT_OK;
1037 struct object_id *bisect_rev;
@@ -1098,7 +1098,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1098 if (oideq(bisect_rev, current_bad_oid)) {
1099 res = error_if_skipped_commits(tried, current_bad_oid);
1100 if (res)
1101 - return res;
1101 + goto cleanup;
1102 printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
1103 term_bad);
1104
@@ -1132,6 +1132,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1132
1133 res = bisect_checkout(bisect_rev, no_checkout);
1134 cleanup:
1135 + free_commit_list(tried);
1136 release_revisions(&revs);
1137 strvec_clear(&rev_argv);
1138 return res;