summaryrefslogtreecommitdiff
path: root/bisect.c
diff options
context:
space:
mode:
Diffstat (limited to 'bisect.c')
-rw-r--r--bisect.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/bisect.c b/bisect.c
index 4713226fad..f6fa5c235f 100644
--- a/bisect.c
+++ b/bisect.c
@@ -28,8 +28,8 @@ static struct oid_array skipped_revs;
static struct object_id *current_bad_oid;
-static const char *term_bad;
-static const char *term_good;
+static char *term_bad;
+static char *term_good;
/* Remember to update object flag allocation in object.h */
#define COUNTED (1u<<16)
@@ -442,9 +442,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
best->next = NULL;
}
*reaches = weight(best);
+ } else {
+ free_commit_list(*commit_list);
}
- free(weights);
*commit_list = best;
+
+ free(weights);
clear_commit_weight(&commit_weight);
}
@@ -456,6 +459,7 @@ static int register_ref(const char *refname, const char *referent UNUSED, const
strbuf_addstr(&good_prefix, "-");
if (!strcmp(refname, term_bad)) {
+ free(current_bad_oid);
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
oidcpy(current_bad_oid, oid);
} else if (starts_with(refname, good_prefix.buf)) {
@@ -556,8 +560,11 @@ struct commit_list *filter_skipped(struct commit_list *list,
tried = &list->next;
} else {
if (!show_all) {
- if (!skipped_first || !*skipped_first)
+ if (!skipped_first || !*skipped_first) {
+ free_commit_list(next);
+ free_commit_list(filtered);
return list;
+ }
} else if (skipped_first && !*skipped_first) {
/* This means we know it's not skipped */
*skipped_first = -1;
@@ -613,7 +620,7 @@ static int sqrti(int val)
static struct commit_list *skip_away(struct commit_list *list, int count)
{
- struct commit_list *cur, *previous;
+ struct commit_list *cur, *previous, *result = list;
int prn, index, i;
prn = get_prn(count);
@@ -625,15 +632,23 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
for (i = 0; cur; cur = cur->next, i++) {
if (i == index) {
if (!oideq(&cur->item->object.oid, current_bad_oid))
- return cur;
- if (previous)
- return previous;
- return list;
+ result = cur;
+ else if (previous)
+ result = previous;
+ else
+ result = list;
+ break;
}
previous = cur;
}
- return list;
+ for (cur = list; cur != result; ) {
+ struct commit_list *next = cur->next;
+ free(cur);
+ cur = next;
+ }
+
+ return result;
}
static struct commit_list *managed_skipped(struct commit_list *list,
@@ -801,6 +816,8 @@ static enum bisect_error handle_bad_merge_base(void)
"between %s and [%s].\n"),
bad_hex, term_bad, term_good, bad_hex, good_hex);
}
+
+ free(good_hex);
return BISECT_MERGE_BASE_CHECK;
}
@@ -848,8 +865,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
rev + 1, &result) < 0)
exit(128);
- for (; result; result = result->next) {
- const struct object_id *mb = &result->item->object.oid;
+ for (struct commit_list *l = result; l; l = l->next) {
+ const struct object_id *mb = &l->item->object.oid;
if (oideq(mb, current_bad_oid)) {
res = handle_bad_merge_base();
break;
@@ -985,7 +1002,7 @@ static void show_commit(struct commit *commit)
* We read them and store them to adapt the messages accordingly.
* Default is bad/good.
*/
-void read_bisect_terms(const char **read_bad, const char **read_good)
+void read_bisect_terms(char **read_bad, char **read_good)
{
struct strbuf str = STRBUF_INIT;
const char *filename = git_path_bisect_terms();
@@ -993,16 +1010,20 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
if (!fp) {
if (errno == ENOENT) {
- *read_bad = "bad";
- *read_good = "good";
+ free(*read_bad);
+ *read_bad = xstrdup("bad");
+ free(*read_good);
+ *read_good = xstrdup("good");
return;
} else {
die_errno(_("could not read file '%s'"), filename);
}
} else {
strbuf_getline_lf(&str, fp);
+ free(*read_bad);
*read_bad = strbuf_detach(&str, NULL);
strbuf_getline_lf(&str, fp);
+ free(*read_good);
*read_good = strbuf_detach(&str, NULL);
}
strbuf_release(&str);
@@ -1024,7 +1045,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
{
struct strvec rev_argv = STRVEC_INIT;
struct rev_info revs = REV_INFO_INIT;
- struct commit_list *tried;
+ struct commit_list *tried = NULL;
int reaches = 0, all = 0, nr, steps;
enum bisect_error res = BISECT_OK;
struct object_id *bisect_rev;
@@ -1091,7 +1112,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
if (oideq(bisect_rev, current_bad_oid)) {
res = error_if_skipped_commits(tried, current_bad_oid);
if (res)
- return res;
+ goto cleanup;
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
term_bad);
@@ -1125,6 +1146,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
res = bisect_checkout(bisect_rev, no_checkout);
cleanup:
+ free_commit_list(tried);
release_revisions(&revs);
strvec_clear(&rev_argv);
return res;