path: root/bisect.c
diff options
authorMartin Ågren <>2017-09-22 23:34:51 (GMT)
committerJunio C Hamano <>2017-09-24 01:05:57 (GMT)
commitb2ccdf7fc15e866a883b706540055b5d05fb9aef (patch)
tree971aea7e1716ea78dbcf3de8d9baf353d019dab3 /bisect.c
parentcb7b29eb67772d08e2365ed07ede9d954d0344c1 (diff)
leak_pending: use `object_array_clear()`, not `free()`
Setting `leak_pending = 1` tells `prepare_revision_walk()` not to release the `pending` array, and makes that the caller's responsibility. See 4a43d374f (revision: add leak_pending flag, 2011-10-01) and 353f5657a (bisect: use leak_pending flag, 2011-10-01). Commit 1da1e07c8 (clean up name allocation in prepare_revision_walk, 2014-10-15) fixed a memory leak in `prepare_revision_walk()` by switching from `free()` to `object_array_clear()`. However, where we use the `leak_pending`-mechanism, we're still only calling `free()`. Use `object_array_clear()` instead. Copy some helpful comments from 353f5657a to the other callers that we update to clarify the memory responsibilities, and to highlight that the commits are not affected when we clear the array -- it is indeed correct to both tidy up the commit flags and clear the object array. Document `leak_pending` in revision.h to help future users get this right. Signed-off-by: Martin Ågren <> Reviewed-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'bisect.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/bisect.c b/bisect.c
index a9fd9fb..fc797f6 100644
--- a/bisect.c
+++ b/bisect.c
@@ -826,7 +826,8 @@ static int check_ancestors(const char *prefix)
/* Clean up objects used, as they will be reused. */
clear_commit_marks_for_object_array(&pending_copy, ALL_REV_FLAGS);
- free(pending_copy.objects);
+ object_array_clear(&pending_copy);
return res;