diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-06-11 11:20:09 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-11 22:15:06 +0200 |
commit | 3199b22e7d8cf8a95b7fac4e4aaf65638256b226 (patch) | |
tree | 07979b04cb6473442278afad4a84aacb60ee4b1a /merge-recursive.c | |
parent | builtin/difftool: plug memory leaks in `run_dir_diff()` (diff) | |
download | git-3199b22e7d8cf8a95b7fac4e4aaf65638256b226.tar.xz git-3199b22e7d8cf8a95b7fac4e4aaf65638256b226.zip |
builtin/merge-recursive: fix leaking object ID bases
In `cmd_merge_recursive()` we have a static array of object ID bases
that we pass to `merge_recursive_generic()`. This interface is somewhat
weird though because the latter function accepts a pointer to a pointer
of object IDs, which requires us to allocate the object IDs on the heap.
And as we never free those object IDs, the end result is a leak.
While we can easily solve this leak by just freeing the respective
object IDs, the whole calling convention is somewhat weird. Instead,
refactor `merge_recursive_generic()` to accept a plain pointer to object
IDs so that we can avoid allocating them altogether.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r-- | merge-recursive.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/merge-recursive.c b/merge-recursive.c index 8c8e8b4868..eff73dac02 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3866,7 +3866,7 @@ int merge_recursive_generic(struct merge_options *opt, const struct object_id *head, const struct object_id *merge, int num_merge_bases, - const struct object_id **merge_bases, + const struct object_id *merge_bases, struct commit **result) { int clean; @@ -3879,10 +3879,10 @@ int merge_recursive_generic(struct merge_options *opt, int i; for (i = 0; i < num_merge_bases; ++i) { struct commit *base; - if (!(base = get_ref(opt->repo, merge_bases[i], - oid_to_hex(merge_bases[i])))) + if (!(base = get_ref(opt->repo, &merge_bases[i], + oid_to_hex(&merge_bases[i])))) return err(opt, _("Could not parse object '%s'"), - oid_to_hex(merge_bases[i])); + oid_to_hex(&merge_bases[i])); commit_list_insert(base, &ca); } if (num_merge_bases == 1) |