Skip to content

Commit 8dd3cb4

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e29ff07 commit 8dd3cb4

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

diff-lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
661661

662662
repo_init_revisions(opt->repo, &revs, NULL);
663663
copy_pathspec(&revs.prune_data, &opt->pathspec);
664+
diff_free(&revs.diffopt);
664665
revs.diffopt = *opt;
665666
revs.diffopt.no_free = 1;
666667

t/t7610-mergetool.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Testing basic merge tool invocation'
1010
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1111
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1212

13+
TEST_PASSES_SANITIZE_LEAK=true
1314
. ./test-lib.sh
1415

1516
# All the mergetool test work by checking out a temporary branch based

0 commit comments

Comments
 (0)