Merge branch 'ma/bisect-leakfix' into maint
Leak fixes. * ma/bisect-leakfix: bisect: fix memory leak when returning best element bisect: fix off-by-one error in `best_bisection_sorted()` bisect: fix memory leak in `find_bisection()` bisect: change calling-convention of `find_bisection()`
This commit is contained in:
commit
03e8004f06
33
bisect.c
33
bisect.c
@ -226,10 +226,11 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
|
|||||||
add_name_decoration(DECORATION_NONE, buf.buf, obj);
|
add_name_decoration(DECORATION_NONE, buf.buf, obj);
|
||||||
|
|
||||||
p->item = array[i].commit;
|
p->item = array[i].commit;
|
||||||
p = p->next;
|
if (i < cnt - 1)
|
||||||
|
p = p->next;
|
||||||
}
|
}
|
||||||
if (p)
|
free_commit_list(p->next);
|
||||||
p->next = NULL;
|
p->next = NULL;
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
free(array);
|
free(array);
|
||||||
return list;
|
return list;
|
||||||
@ -360,28 +361,29 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
|
|||||||
return best_bisection_sorted(list, nr);
|
return best_bisection_sorted(list, nr);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct commit_list *find_bisection(struct commit_list *list,
|
void find_bisection(struct commit_list **commit_list, int *reaches,
|
||||||
int *reaches, int *all,
|
int *all, int find_all)
|
||||||
int find_all)
|
|
||||||
{
|
{
|
||||||
int nr, on_list;
|
int nr, on_list;
|
||||||
struct commit_list *p, *best, *next, *last;
|
struct commit_list *list, *p, *best, *next, *last;
|
||||||
int *weights;
|
int *weights;
|
||||||
|
|
||||||
show_list("bisection 2 entry", 0, 0, list);
|
show_list("bisection 2 entry", 0, 0, *commit_list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Count the number of total and tree-changing items on the
|
* Count the number of total and tree-changing items on the
|
||||||
* list, while reversing the list.
|
* list, while reversing the list.
|
||||||
*/
|
*/
|
||||||
for (nr = on_list = 0, last = NULL, p = list;
|
for (nr = on_list = 0, last = NULL, p = *commit_list;
|
||||||
p;
|
p;
|
||||||
p = next) {
|
p = next) {
|
||||||
unsigned flags = p->item->object.flags;
|
unsigned flags = p->item->object.flags;
|
||||||
|
|
||||||
next = p->next;
|
next = p->next;
|
||||||
if (flags & UNINTERESTING)
|
if (flags & UNINTERESTING) {
|
||||||
|
free(p);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
p->next = last;
|
p->next = last;
|
||||||
last = p;
|
last = p;
|
||||||
if (!(flags & TREESAME))
|
if (!(flags & TREESAME))
|
||||||
@ -397,12 +399,16 @@ struct commit_list *find_bisection(struct commit_list *list,
|
|||||||
/* Do the real work of finding bisection commit. */
|
/* Do the real work of finding bisection commit. */
|
||||||
best = do_find_bisection(list, nr, weights, find_all);
|
best = do_find_bisection(list, nr, weights, find_all);
|
||||||
if (best) {
|
if (best) {
|
||||||
if (!find_all)
|
if (!find_all) {
|
||||||
|
list->item = best->item;
|
||||||
|
free_commit_list(list->next);
|
||||||
|
best = list;
|
||||||
best->next = NULL;
|
best->next = NULL;
|
||||||
|
}
|
||||||
*reaches = weight(best);
|
*reaches = weight(best);
|
||||||
}
|
}
|
||||||
free(weights);
|
free(weights);
|
||||||
return best;
|
*commit_list = best;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int register_ref(const char *refname, const struct object_id *oid,
|
static int register_ref(const char *refname, const struct object_id *oid,
|
||||||
@ -954,8 +960,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
|
|||||||
|
|
||||||
bisect_common(&revs);
|
bisect_common(&revs);
|
||||||
|
|
||||||
revs.commits = find_bisection(revs.commits, &reaches, &all,
|
find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr);
|
||||||
!!skipped_revs.nr);
|
|
||||||
revs.commits = managed_skipped(revs.commits, &tried);
|
revs.commits = managed_skipped(revs.commits, &tried);
|
||||||
|
|
||||||
if (!revs.commits) {
|
if (!revs.commits) {
|
||||||
|
12
bisect.h
12
bisect.h
@ -1,9 +1,15 @@
|
|||||||
#ifndef BISECT_H
|
#ifndef BISECT_H
|
||||||
#define BISECT_H
|
#define BISECT_H
|
||||||
|
|
||||||
extern struct commit_list *find_bisection(struct commit_list *list,
|
/*
|
||||||
int *reaches, int *all,
|
* Find bisection. If something is found, `reaches` will be the number of
|
||||||
int find_all);
|
* commits that the best commit reaches. `all` will be the count of
|
||||||
|
* non-SAMETREE commits. If nothing is found, `list` will be NULL.
|
||||||
|
* Otherwise, it will be either all non-SAMETREE commits or the single
|
||||||
|
* best commit, as chosen by `find_all`.
|
||||||
|
*/
|
||||||
|
extern void find_bisection(struct commit_list **list, int *reaches, int *all,
|
||||||
|
int find_all);
|
||||||
|
|
||||||
extern struct commit_list *filter_skipped(struct commit_list *list,
|
extern struct commit_list *filter_skipped(struct commit_list *list,
|
||||||
struct commit_list **tried,
|
struct commit_list **tried,
|
||||||
|
@ -397,8 +397,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
|
|||||||
if (bisect_list) {
|
if (bisect_list) {
|
||||||
int reaches = reaches, all = all;
|
int reaches = reaches, all = all;
|
||||||
|
|
||||||
revs.commits = find_bisection(revs.commits, &reaches, &all,
|
find_bisection(&revs.commits, &reaches, &all, bisect_find_all);
|
||||||
bisect_find_all);
|
|
||||||
|
|
||||||
if (bisect_show_vars)
|
if (bisect_show_vars)
|
||||||
return show_bisect_vars(&info, reaches, all);
|
return show_bisect_vars(&info, reaches, all);
|
||||||
|
Loading…
Reference in New Issue
Block a user