bisect: use leak_pending flag

Instead of creating a copy of the list of pending objects, copy the struct object_array that points to it, turn on leak_pending, and thus cause prepare_revision_walk to leave it to us. And free it once we're done. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 1, 2011 at 18:01 UTC 353f5657a8263bf4159d7e0450fb891df5e2b4c6
1 file changed +8 -5
bisect.c
+8 -5
@@ -823,12 +823,14 @@ static int check_ancestors(const char *prefix)
823 bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
824
825 /* Save pending objects, so they can be cleaned up later. */
826 - memset(&pending_copy, 0, sizeof(pending_copy));
827 - for (i = 0; i < revs.pending.nr; i++)
828 - add_object_array(revs.pending.objects[i].item,
829 - revs.pending.objects[i].name,
830 - &pending_copy);
826 + pending_copy = revs.pending;
827 + revs.leak_pending = 1;
828
829 + /*
830 + * bisect_common calls prepare_revision_walk right away, which
831 + * (together with .leak_pending = 1) makes us the sole owner of
832 + * the list of pending objects.
833 + */
834 bisect_common(&revs);
835 res = (revs.commits != NULL);
836
@@ -837,6 +839,7 @@ static int check_ancestors(const char *prefix)
839 struct object *o = pending_copy.objects[i].item;
840 clear_commit_marks((struct commit *)o, ALL_REV_FLAGS);
841 }
842 + free(pending_copy.objects);
843
844 return res;
845 }