summaryrefslogtreecommitdiff
path: root/diff-lib.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-11-05 07:17:00 +0100
committerJunio C Hamano <gitster@pobox.com>2024-11-04 22:37:52 -0800
commit8dd3cb4b45d06959f3344f02b2d45a4ccf8207d8 (patch)
treef41ba7c0478f6829dc00b8135b7ffedfc3a109ea /diff-lib.c
parente29ff075e082ecdc6ee85baea83d32d4a055d186 (diff)
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>
Diffstat (limited to 'diff-lib.c')
-rw-r--r--diff-lib.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 6b14b95962..3cf353946f 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -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;