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 | Merge branch 'rj/no-sign-compare' (diff) | |
parent | pack-bitmap[-write]: use `object_array_clear()`, don't leak (diff) | |
download | tgif-69c54c72845ebc686d0f4bdd8d44b06f799b0a80.tar.xz |
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, |