diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-29 11:23:43 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-29 11:23:43 +0900 |
commit | 69c54c72845ebc686d0f4bdd8d44b06f799b0a80 (patch) | |
tree | bbd4e768952cbd26dd7ddaec0ab915fcda9987a8 /builtin/checkout.c | |
parent | 14a8168e2fed3934f1f9afb286f1c64345d06790 (diff) | |
parent | 4d01a7fa65c50e817a935396432e199b7a565f53 (diff) | |
download | git-69c54c72845ebc686d0f4bdd8d44b06f799b0a80.tar.gz |
Merge branch 'ma/leakplugs'
Memory leaks in various codepaths have been plugged.
* ma/leakplugs:
pack-bitmap[-write]: use `object_array_clear()`, don't leak
object_array: add and use `object_array_pop()`
object_array: use `object_array_clear()`, not `free()`
leak_pending: use `object_array_clear()`, not `free()`
commit: fix memory leak in `reduce_heads()`
builtin/commit: fix memory leak in `prepare_index()`
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index d091f06274..3345a0d16f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -797,9 +797,14 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) for_each_ref(add_pending_uninteresting_ref, &revs); add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING); + /* Save pending objects, so they can be cleaned up later. */ refs = revs.pending; revs.leak_pending = 1; + /* + * prepare_revision_walk (together with .leak_pending = 1) makes us + * the sole owner of the list of pending objects. + */ if (prepare_revision_walk(&revs)) die(_("internal error in revision walk")); if (!(old->object.flags & UNINTERESTING)) @@ -807,8 +812,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) else describe_detached_head(_("Previous HEAD position was"), old); + /* Clean up objects used, as they will be reused. */ clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS); - free(refs.objects); + + object_array_clear(&refs); } static int switch_branches(const struct checkout_opts *opts, |