diff-lib: fix leaking diffopts in `do_diff_cache()`
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>
Patrick Steinhardt committed
Nov 5, 2024 at 07:17 UTC
8dd3cb4b45d06959f3344f02b2d45a4ccf8207d8
2 files changed
+2
diff-lib.c
+1
@@ -661,6 +661,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
661
662
repo_init_revisions(opt->repo, &revs, NULL);
663
copy_pathspec(&revs.prune_data, &opt->pathspec);
664
+ diff_free(&revs.diffopt);
665
revs.diffopt = *opt;
666
revs.diffopt.no_free = 1;
667
t/t7610-mergetool.sh
+1
@@ -10,6 +10,7 @@ Testing basic merge tool invocation'
10
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
13
+TEST_PASSES_SANITIZE_LEAK=true
14
. ./test-lib.sh
15
16
# All the mergetool test work by checking out a temporary branch based