]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()
authorElijah Newren <newren@gmail.com>
Tue, 21 Apr 2026 00:26:09 +0000 (00:26 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Apr 2026 23:22:19 +0000 (16:22 -0700)
clear_or_reinit_internal_opts() is responsible for cleaning up the
various data structures in merge_options_internal.  It already handles
many renames-related structures (dirs_removed, dir_renames,
relevant_sources, cached_pairs, deferred, etc.) but does not free
renames->pairs[].queue.

In the normal code path, resolve_and_process_renames() frees
pairs[s].queue and reinitializes it with diff_queue_init() before
clear_or_reinit_internal_opts() runs, so the omission is harmless.
However, if collect_merge_info() encounters an error and returns early
(before resolve_and_process_renames() is ever called), any diff pairs
already queued by collect_rename_info()/add_pair() will have their
backing array leaked.

Fix this by freeing renames->pairs[].queue in the cleanup function.
In the normal path the pointer is already NULL (from the earlier
diff_queue_init() in resolve_and_process_renames()), so free(NULL) is
a safe no-op.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-ort.c

index 74e9636020fe4085024095b1715480cf93daba94..8f911cb63979ebaf9b1683390eac9577eb87b50e 100644 (file)
@@ -728,6 +728,8 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
                strintmap_clear_func(&renames->deferred[i].possible_trivial_merges);
                strset_clear_func(&renames->deferred[i].target_dirs);
                renames->deferred[i].trivial_merges_okay = 1; /* 1 == maybe */
+               free(renames->pairs[i].queue);
+               diff_queue_init(&renames->pairs[i]);
        }
        renames->cached_pairs_valid_side = 0;
        renames->dir_rename_mask = 0;