mirror of
https://github.com/git/git.git
synced 2024-11-27 03:53:55 +08:00
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 as that field is overwritten we won't ever free that. Plug the memory leak by releasing the diffopts before we overwrite them. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
parent
ab28bc860f
commit
27a1c1fd42
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user