merge_trees(): ensure that the callers release output buffer
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 1 Aug 2016 11:44:53 +0000 (13:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Aug 2016 18:45:30 +0000 (11:45 -0700)
The recursive merge machinery accumulates its output in an output
buffer, to be flushed at the end of merge_recursive(). At this point,
we forgot to release the output buffer.

When calling merge_trees() (i.e. the non-recursive part of the recursive
merge) directly, the output buffer is never flushed because the caller
may be merge_recursive() which wants to flush the output itself.

For the same reason, merge_trees() cannot release the output buffer: it
may still be needed.

Forgetting to release the output buffer did not matter much when running
git-checkout, or git-merge-recursive, because we exited after the
operation anyway. Ever since cherry-pick learned to pick a commit range,
however, this memory leak had the potential of becoming a problem.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
merge-recursive.c
sequencer.c
index 07dea3bc814ba26edd13a0e3ae73b3298958c3e9..8d852d458514ca8d2e9553bec6a818b140b0e478 100644 (file)
@@ -573,6 +573,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                                exit(128);
                        ret = reset_tree(new->commit->tree, opts, 0,
                                         writeout_error);
+                       strbuf_release(&o.obuf);
                        if (ret)
                                return ret;
                }
index ec50932210807b2fd1f14e11694d00c7e2c21d15..9e527dec62a71940174a31a3a8040f2498ad6c73 100644 (file)
@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,
                commit_list_insert(h2, &(*result)->parents->next);
        }
        flush_output(o);
+       if (!o->call_depth && o->buffer_output < 2)
+               strbuf_release(&o->obuf);
        if (show(o, 2))
                diff_warn_rename_limit("merge.renamelimit",
                                       o->needed_rename_limit, 0);
index 286a4358520429bc8433eaf192beca9690c71ade..ec50519df92eb50f74db8e7db05f35d0ebb913b2 100644 (file)
@@ -293,6 +293,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
        clean = merge_trees(&o,
                            head_tree,
                            next_tree, base_tree, &result);
+       strbuf_release(&o.obuf);
        if (clean < 0)
                return clean;