]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff-lib: fix leaking diffopts in `do_diff_cache()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 5 Nov 2024 06:17:00 +0000 (07:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Nov 2024 06:37:52 +0000 (22:37 -0800)
In `do_diff_cache()` we initialize a new `rev_info` and then overwrite
its `diffopt` with a user-provided set of options. This can leak memory
because `repo_init_revisions()` may end up allocating memory for the
`diffopt` itself depending on the configuration. And since that field is
overwritten we won't ever free it.

Plug the memory leak by releasing the diffopts before we overwrite them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-lib.c
t/t7610-mergetool.sh

index 6b14b9596299f1cec3a02fe9d4098725f7fea04b..3cf353946f51ca4ef96ab4a2add7cd97eacf258e 100644 (file)
@@ -661,6 +661,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
 
        repo_init_revisions(opt->repo, &revs, NULL);
        copy_pathspec(&revs.prune_data, &opt->pathspec);
+       diff_free(&revs.diffopt);
        revs.diffopt = *opt;
        revs.diffopt.no_free = 1;
 
index 22b3a85b3e960e4d40024179b1fbaef3355d304d..5c5e79e99052c324fcf47556174045e6d7af3c91 100755 (executable)
@@ -10,6 +10,7 @@ Testing basic merge tool invocation'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # All the mergetool test work by checking out a temporary branch based